Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing standalone component initializers #2

Open
pirogoeth opened this issue Feb 18, 2018 · 0 comments
Open

Reusing standalone component initializers #2

pirogoeth opened this issue Feb 18, 2018 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@pirogoeth
Copy link
Owner

Currently, a registered component's init function will be automatically injected during initialization of the function regardless of if the function is decorated with an Injector. Given this example:

inject: Injector = make_injector(get_registry())

@inject
def initialize_component(c: SomeComponent) -> Any:
    return OtherComponent(c)

register_component(
    cls=OtherComponent,
    init=initialize_component,
    persist=False,
    registry=get_registry(),
)

When initialize_component is called by diecast during injection, the initialize_component function will be injected twice. Best case, it's just additional overhead. Worst case, it attempts to rebind the function when parameters are already bound, overwriting the first injected value or just failing.


The created injector should "mark" the injected function, so that the component initializer knows not to re-inject dependencies into the initializer function.

@pirogoeth pirogoeth added bug Something isn't working good first issue Good for newcomers labels Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant