You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of now Generics are not supported (see #175). So as a workaround I do the following:
classThingDoer(Generic[X]):
@injectdef__init__(a_instance: A, b_instance: B) # <-- workaround for no generic args to A and B
...
classAFoo(A[Foo]):
"""this class has no body"""classBFoo(B[Foo]):
"""this class has no body"""classABar(A[Bar]):
"""this class has no body"""classBBar(B[Bar]):
"""this class has no body"""defconfigure_foo(binder):
binder.bind(A, AFoo)
binder.bind(B, BFoo)
injector_foo=Injector([configure_foo])
defconfigure_bar(binder):
binder.bind(A, ABar)
binder.bind(B, BBar)
injector_bar=Injector([configure_bar])
foo_doer=injector_foo.get(ThingDoer)
bar_doer=injector_bar.get(ThingDoer)
Question is: Is it an antipattern to have multiple instances of Injector?
Should I instead use the inject decorator on the child classes directly?
The text was updated successfully, but these errors were encountered:
hf-kklein
changed the title
Is it an antipattern to have multiple instances of Injector?
Is it an antipattern to have multiple instances of Injector (because of missing Generics support)?
Jun 2, 2023
I'd say that there's no simple answer to your question, but rather that it depends on your situation. Do whatever suits you best. I've successfully used parent/child injectors for simliar cases, but there are probably cases where either of your options are better.
I'd say that there's no simple answer to your question, but rather that it depends on your situation. Do whatever suits you best. I've successfully used parent/child injectors for simliar cases, but there are probably cases where either of your options are better.
I have an application. It has multiple purposes:
There are helper classes which I'll just call
A
,B
, ...For doing Foo or Bar I'm having a generic
super()
type:As of now Generics are not supported (see #175). So as a workaround I do the following:
Question is: Is it an antipattern to have multiple instances of
Injector
?Should I instead use the inject decorator on the child classes directly?
The text was updated successfully, but these errors were encountered: