python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Question: Create an instance of providers.Singleton at the same time as fastapi starts.

Open satodaiki opened this issue 4 years ago • 0 comments

Hello.

As the title suggests, what should I do with the definition of providers.Singleton that instantiates at the same time as fastapi starts!

I want to generate the following "manager" at the start of fastapi. (Dependency injection of application_service in manager may be implemented incorrectly.)

class Container(containers.DeclarativeContainer):

    application_service = providers.Factory(
        ApplicationService,
    )

    manager = providers.Singleton(
        Manager,
        application_service=application_service(), # Inject the above application_service dependency.
    )

Do you have any good ideas?

satodaiki avatar Apr 20 '21 06:04 satodaiki