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
Q: Can Configuration values be made required? #341
Comments
I wonder if maybe what I want is a custom provider that behaves as a stricter version of |
Hey @ms-lolo , that doesn't work out of the box, but that's a good idea. I'll think how it could be implemented. The wild guess I have now is to make something like this: class MyContainer(DeclarativeContainer):
config = Configuration()
config.something_important.required()
some_client = Singleton(SomeClient, config.something_important) There also could be a strict mode for |
I have released version |
Closing the issue. Reopen if needed. |
@ms-lolo , thanks for suggesting the feature! |
this seems to solve my problem, thank a lot! |
Glad to hear that! Thank you again |
Couldn't find an example of this in the docs but I am trying to ensure that the system fails fast if the container hasn't been properly configured when the necessary provider is called. For example:
Right now, if I forget to set
mycontainer.config.something_important
before callingmycontainer.some_client()
, thenSomeClient
will be givenNone
as its parameter which is actually worse than forgetting to pass the argument at all because Python will allow it even if it's not an optional parameter. I don't want to sprinkle my classes withsomething_important is None
checks.What I really want is to be able to specify the exact keys I would expect in a Configuration provider and have the Container initialization fail if those values are not provided. Do you have any suggestions?
The text was updated successfully, but these errors were encountered: