Giter Club home page Giter Club logo

Comments (5)

davidparsson avatar davidparsson commented on July 26, 2024

I'm not entirely sure I get your use case, but I think the one of the closest thing we have is creating new types with NewType and binding different NewTypes to different instances. I've used that successfully. If the modules don't interact with each other, having parent/child injectors is another way of partially sharing injector configuration. Would any of those work for you?

from injector.

r2rstep avatar r2rstep commented on July 26, 2024

NewType for sure will work but it introduces boilerplate, even though minimal, so it's not optimal.

To demonstrate my use case:

# common.container
class Container(injector.Module):
    def configure(self, binder):
        binder.bind(MessageBus, to=MessageBus)


# module_a.container
class Container(injector.Module):
    def configure(self, binder):
        binder.bind(SomeCommonBase, to=module_a.Concrete)

container = injector.Injector([Container(), common.container.Container()])


# module_b.container
class Container(injector.Module):
    def configure(self, binder):
        binder.bind(SomeCommonBase, to=module_b.Concrete)

container = injector.Injector([Container(), common.container.Container()])


# common.message_bus
class MessageBus:
    @injector.inject
    def __init__(self, module_specific_instance: SomeCommonBase):
        ...

from injector.

jstasiak avatar jstasiak commented on July 26, 2024

Hey @r2rstep, I'm also not entirely surely I understand this.

In the code sample you included above, where would the "pick the Injector instance" logic go?

I feel like this misses some context and possibly a clarification of what problem is being solved here. In general I'd not expect a piece a single application context to define or use multiple Injector instances.

from injector.

jstasiak avatar jstasiak commented on July 26, 2024

After re-reading I think I understand it better now. I believe if you want to dispatch to multiple Injector instances you may need to do it manually for the time being (get access to the instance, call get() on it).

I'd maybe try to put all of that in a single Injector instance so your various modules could coexist there but I understand it may not be feasible.

from injector.

r2rstep avatar r2rstep commented on July 26, 2024

yeah, it's more like a feature request :) The case is for modular monolith where each module should define own dependencies.

Anyway, thanks for taking time to respond :)

from injector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.