Skip to content

Make Closing marker working with providers that contains a resource as argument #633

Closed
@kiriharu

Description

@kiriharu

Hi!

Is it possible to make the Closing marker work with all types providers that contain a resource inside? For example, in the following code, the Closing marker does not work:

# handlers
@inject
async def create_project(
    request: web.Request,
    project_repository: ProjectRepository = Closing[Provide[Container.project_repository]],
) -> web.Response:
    ....
# di
class Container(containers.DeclarativeContainer):
    db_session = providers.Resource(get_session, database=db)
    project_repository = providers.Factory(
        ProjectRepository,
        session=db_session
    )

At this moment it will work if we add a separate resource argument to handler:

@inject
async def create_project(
    request: web.Request,
    project_repository: Session = Closing[Provide[Container.db_session]],
    project_repository: ProjectRepository = Closing[Provide[Container.project_repository]],
) -> web.Response:
    ....

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions