This question originates from a question that I asked two days ago. I implemented my own error handler which extends DefaultHttpErrorHandler
. DefaultHttpErrorHandler
extends HttpErrorHandler
which is also used as a parameter errorHandler: HttpErrorHandler
in the WebJarAssets
class. First I thought I had a flaw in my design, but James Ward commented that it seems like that I am doing things right.
Long story short, I need to know how I can activate circular dependencies. Unfortunately, there is no example code listed in the Play documentation, so I have no idea where I should set disableCircularProxies(false)
.
There are a couple of options to get rid of circular dependencies. For a longer chain, A -> B -> C -> D -> A , if one of the references is removed (for instance, the D -> A reference), the cyclic reference pattern is broken, as well. For simpler patterns, such as A -> B -> A , refactoring may be necessary.
To reduce or eliminate circular dependencies, architects must implement loose component coupling and isolate failures. One approach is to use abstraction to break the dependency chain. To do this, you introduce an abstracted service interface that delivers underlying functionality without direct component coupling.
A circular dependency occurs when two classes depend on each other. For example, class A needs class B, and class B also needs class A. Circular dependencies can arise in Nest between modules and between providers. While circular dependencies should be avoided where possible, you can't always do so.
In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive.
You need a custom GuiceApplicationLoader
like:
import play.api.ApplicationLoader
import play.api.inject.guice.{GuiceApplicationLoader, GuiceApplicationBuilder}
class CustomApplicationLoader extends GuiceApplicationLoader {
override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = {
super.builder(context).disableCircularProxies(false)
}
}
And tell Play to use it in application.conf
:
play.application.loader = "CustomApplicationLoader"
Full code example: https://github.com/webjars/webjars-play/tree/cicular-deps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With