Skip to content

Question about the example code and intended use #229

@chriscoindeskindices

Description

@chriscoindeskindices

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions