I'm using Guice dependency injection in my Play 2.5 application, along with SecureSocial. SecureSocial's Registration controller calls a (deprecated) Play.current.configuration value eagerly, which so far as I can tell is incompatible with DI, and therefore I get a java.lang.RuntimeException: There is no started application error immediately at runtime. Is there a way I can ensure that Play.current.configuration is bound by Guice and thus available to the SecureSocial library? Or is my only option to re-write the Registration controller to call the configuration lazily?
SecureSocial is on the way to support Play 2.5
There is a 3.0-M6 version (12 days ago), did you try it?
https://groups.google.com/forum/#!topic/securesocial/YcrAay9eO2M
https://github.com/jaliss/securesocial
Related
I am trying to inject a UnitOfWork into my repositories using Guice in Play. I am trying to configure the UnitOfWork to be RequestScoped, but there does not seem to be a way to do this.
I have googled and been on stack overflow for a while now and have not come across a clear answer for this. What is the state of RequestScoped for Play in 2019?
Play Framework is Stateless by default. From its Web Page:
Play is based on a lightweight, stateless, web-friendly architecture.
So everything that you inject with Guice is created newly.
There is an exception if you annotate a class with Singleton then this class will be injected only once per Node.
I'm using Autofac IOC in my Asp.Net MVC Application. I have seen a circular dependency between services detected in run time (even not detected in building/rebuilding project). Why this happen in run time?
Autofac is not a compiler or compiler plugin. It is a library that uses reflection to gather information only available at runtime to build object graphs, and it only does so when you start your application.
If you want compiler support: don't use a DI Container, but revert to using Pure DI, which means you build your object graphs by hand (using new statements) inside the Composition Root.
I am using the built in cache in a scala playframework 2.4 application.
During development, I would like to be able to deactivate the whole cache temporarily.
How would I do that?
If you're using play's default cache implementation, which is EhCache, you can run your play application with net.sf.ehcache.disabled=true in order to turn off the cache. Of course this is not so desirable for automated testing and only applicable to EhCache implementation.
In my play 2.1 app I was using Guice, but to bind my interfaces to implementations for IoC I was using this library:
https://github.com/sptz45/sse-guice
Is this still needed for play 2.4? If not, do they have their own helpers that are like sse-guice?
As the What’s new in Play 2.4 page states:
Play now supports dependency injection out of the box.
You have the following options for DI in Play 2.4.x:
An implementation that uses Guice out of the box
An abstraction that allows other JSR 330 implementations to be plugged in
All Play components can be instantiated using plain constructors or factory methods
Traits that instantiate Play components that can be mixed together in a cake pattern like style to assist with compile time dependency injection
You can read more about Play’s dependency injection support for Scala.
As of Play 2.4 the Plugin class is deprecated and one should use the Module class instead.
I've understood file play.plugins is no longer necessary and custom modules should be registered in application.conf as documented here.
But how do I migrate my old plugins? The Module class doesn't contain methods onStart and onStop... Is there an example somewhere?
This pull request has the full Redis plugin migration from 2.3 to 2.4. They use the constructor for the onStart and ApplicationLifecycle for the onStop in SedisPoolProvider.
https://github.com/typesafehub/play-plugins/pull/148/files
Documentation explains that the goal is to provide bindings in a DI framework agnostic way. This is the reason I believe there is no trait with onStart and onStop to implement. The agnostic way is to use constructor and/or by injecting a lifecycle module like ApplicationLifecycle.