Skip to content

Support Scoped dependency injection when underlying container does #1399

Open
@hwoodiwiss

Description

@hwoodiwiss

Is your feature request related to a problem? Please describe.

When handling messages, I often ending up having to writing factories for cases that in, for example, ASP.NET I'd just be able to use a scoped service, as the DI container will handle disposing services when the scope is disposed at the end of a request.

I feel like that same paradigm can be applied here as well, with the scope wrapping resolution and execution of the handler.

Describe the solution you'd like

When the underlying DI container supports it, I would like to be able to resolve handlers within a service scope so that their dependencies can have their lifetimes managed by the DI service scope.

Describe alternatives you've considered

In the past I've used a wrapper approach, in which the wrapper handler has an IServiceProvider injected, which I then use to create a scope and resolve the actual handler. This approach is quite clunky, and means I still can't use scoped services in the "outer" handler without potentially leaking memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions