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
from dependency_injector import containers, providers
from trader.core.args_manager import ArgsManager
from trader.core.api import Api
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
args_manager = providers.Singleton(
ArgsManager,
)
api = providers.Singleton(
Api,
)
from dependency_injector.wiring import Provide, inject
class ArgsManager:
@inject
def __init__(self, api = Provide["api"]):
print(api)
class Api:
def __init__(self):
pass
print(api) gives instance of dependency_injector.wiring.Provide instead of Api
if I add wire, it gives circular import error.
ArgsManager requires Container and Container requires ArgsManager
from dependency_injector.wiring import Provide, inject
class ArgsManager:
@inject
def __init__(self, api = Provide["api"]):
print(api)
if __name__ == "__main__":
container = Container()
container.wire(modules=[__name__])
I'm facing the same issue. I almost get the sense you can only inject objects that don't depend on the container (or any of their dependencies do).... but that makes it so much weaker than other DI frameworks I've used. Does anyone have some solution or another recommendation?
I am facing the circular dependency issue:
print(api)
gives instance of dependency_injector.wiring.Provide instead of Apiif I add wire, it gives circular import error.
ArgsManager requires Container and Container requires ArgsManager
How to solve this ?
Originally posted by @krunaldodiya in #327 (comment)
The text was updated successfully, but these errors were encountered: