-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"No valid constructors" if you only need Configuration #8474
Comments
One simple solution for the confusion caused by "No valid constructors" would be to make the error message say what constructors would be valid. It would certainly mean less work here :) |
Hi Kubukoz,
Yes, that would be a better error message. Do you want to submit a pull request to improve that? Best. |
Sure, should be a quick one. |
Also since we are deprecating the Java
Nothing is already bound at that point. The binding happens all at once when Play creates the injector with all the bindings aggregated from all your modules. The The constructors that take |
It is not present in the master branch anymore since Java deprecated APIs were removed. :-) |
So the action item here is to just change the error message to list all the valid constructors. It may also be worth updating the scaladoc for I think if I were to design things from scratch I'd have a single type injected into the constructor, something like: trait ModuleContext {
def config: com.typesafe.config.Config
def environment: play.api.Environment
final def configuration: play.api.Configuration = play.api.Configuration(config)
final def javaEnvironment: play.Environment = new play.Environment(environment)
} Then your module would accept a I'm not sure it's worth the breaking changes for that, though. Just wanted to throw the idea out there. |
Hi, can i work on it? |
Hi @daric93, Yes, thanks for that. |
Hello, @marcospereira, @kubukoz , What is the expected output for the exception message? Something along these lines would be acceptable?
|
We should list the valid constructors. Something like:
|
Hello, I have a simple implementation that fixes this problem |
This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
…tors" This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
…tors" This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
Is there a better solution here that doesn't flag |
Play Version (2.5.x / etc)
2.6.13
API (Scala / Java / Neither / Both)
Scala API
Expected Behavior
Actual Behavior
"No valid constructor" in the logs.
I was surprised to see that it didn't work, because I had a similar module already, only that one required both
Environment
andConfiguration
. After some time of debugging, I tried passing both, and it worked.I traced the origin of this to the implementation of
play.api.inject.Modules#constructModule
:If the reason for not supporting a single-argument constructor with just
Configuration
is that there would have to be support for all the possible combinations (which would probably bring 2-3x the amount of code that already is there), then I think there could be something done to change the way Play tries to construct a module - maybe allowing to use@Inject()
on the constructor and bring anything that is already bound? (essentially making a module yet another component/bean)The text was updated successfully, but these errors were encountered: