-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
The example code on the main page:
>>> def configure_for_testing(binder):
... configuration = Configuration(':memory:')
... binder.bind(Configuration, to=configuration, scope=singleton)
and
>>> injector = Injector([configure_for_testing, DatabaseModule()])
>>> handler = injector.get(RequestHandler)
>>> tuple(map(str, handler.get()[0])) # py3/py2 compatibility hack
('hello', 'world')
etc etc.
In this example it looks like we use binding through a global function, we create a module, and we create a class with an @Inject annotation.
Was this simply to illustrate all the ways that are possible to use this package and not a realistic example? For me, I've done everything in a module so my classes being injected are decoupled from the injector package and annotations. I view the module almost like a docker container + factory + builder pattern where everything is encapsulated and I use it as a black box by just saying "give me object" and it does the rest.
To me this is preferable for my use case, but I just want to make sure I'm not missing something I should be doing. Thanks.
Metadata
Metadata
Assignees
Labels
No labels