Skip to content

Q: Can Configuration values be made required? #341

@ms-lolo

Description

@ms-lolo

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:

class MyContainer(DeclarativeContainer):

    config = Configuration()

    some_client = Singleton(SomeClient, config.something_important)

Right now, if I forget to set mycontainer.config.something_important before calling mycontainer.some_client(), then SomeClient will be given None 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 with something_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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions