-
-
Notifications
You must be signed in to change notification settings - Fork 337
-
Hello.
-
I'm trying to create a Controller object that I expect to be taken from the container to the initializer of the SomeEntity class and so that it is built automatically from the arguments that are next to it (arg1, arg2) in the initializer of the SomeEntity class. I would also like to pass these arguments to the next object (SomeCls) inside the Controller - can I do such a chain?
What should I substitute for the '???' signs? Tried dynamic container but didn't work -
Why don’t I see the difference between the @Inject decorator attached to the initializer of the SomeEntity class and without this decorator? All classes are in different modules
from dependency_injector import providers, containers
from dependency_injector.wiring import inject, Provide
class SomeCls:
def __init__(self, arg1, arg2):
self.arg = arg1
self.arg2 = arg2
class Controller:
def __init__(self, arg1, arg2, some_cls: SomeCls):
self.a = arg1
self.b = arg2
self.cls = some_cls
class Container(containers.DeclarativeContainer):
controller = providers.Factory(
Controller,
arg1=???,
arg2=???,
some_cls=providers.Factory(
SomeCls,
arg1=???,
arg2=???,
)
)
class SomeEntity:
@inject
def __init__(self, arg1, arg2, controller: Controller = Provide[Container.controller]):
self.arg = arg1
self.arg2 = arg2
self.controller = controller
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment