-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add abstract injection without importing concrete impl #19
Comments
I assume your interface and implementations are on different files/modules and they're decorated with register/abstract. The issue that might come up is that if that module is never imported, the container.register decorator call is never triggered so the container does not know about that object. To fix this do one of the following on app startup: Call You can also just bring them into scope by using What framework are you using this with if you don't mind me asking? |
Correct, i have located abstract class, and concrete impls, on different packages (nested catalogs) and decorated them with abstract and register(qualifier) accordingly. So basically speaking, i need to call I've managed to do some hack by naming the qualifiers as the classes, and invoke them via I am using a lot of there, but to specify a few: aio_pika, fastapi, pydantic.. and so on. Thank you for the response and guidance. |
Yes, you'd call that on your application's entrypoint right after everything is set up.
Something like this: from wireup import container, warmup_container
from some_app import services
def cerate_app():
app = ...
# perform rest of set up
# ...
warmup_container(container, service_modules=[services])
return app Take a look at the Flask and FastAPI integration docs. You can replace the integration method call with warmup container(Integration does warmup + a few extra things depending on framework). Additionally You can import all your services and call from services import A, B, C
from wireup import container
container.abstract(A)
container.register(B)
container.register(C, qualifier="foo") I do recommend doing the warmup if you have a long-lasting process such as a web api. Let me know if that answers your question. |
Currently from my experience, when we are using
Annotated[AbstractClass, Wire(qualifier=Any)]
- we still need to import redundant Concrete Impl to scope, where @autowire is performed. If such import is not performed, user will experiencewireup.errors.UnknownQualifiedServiceRequestedError
It would be nice for this library to have such feature, or at least, have an docs for this cause, to not import redundant concrete classes, but have a workaround.
The text was updated successfully, but these errors were encountered: