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

Use scoped registration outside scope #636

anton-putau opened this Issue Nov 19, 2018 · 2 comments


2 participants

anton-putau commented Nov 19, 2018

I have my own simple service bus. I send command, receive it and invoke handler. Handler I am resolving using small abstraction over any DI container

public class DependencyContainer : IDependencyContainer
    private readonly Container _container;

    public DependencyContainer(Container container)
        _container = container;

    public object GetService(Type serviceType)
        return _container.GetInstance(serviceType);

My problem is next: my handlers are registered as Async Scope, so I cant do something like this (inside endpoint listener) - DependencyContainer.Resolve(MyHandler ) -

The MyHandler is registered as 'Async Scoped' lifestyle, but the instance is requested outside the context of an active (Async Scoped) scope

I need do something next -

using (AsyncScopedLifestyle.BeginScope(container)) {
     var handler = container.Resolve(MyHandler )

I cant understand how to work with scope. I cant place this code inside endpoint because I should use simpleinjector directly. I can't place this code inside DependencyContainer - it's not the task of DependencyContainer. Could any point me how to deal with this?


If it was something like CreateChildContainer and per container lifetime then I will have no problem. Using block is a headache for me.


This comment has been minimized.


dotnetjunkie commented Nov 19, 2018

I made the following comment on your SO question:

What you wish to accomplish, is not possible. You will either have to change your abstraction or apply scoping on a different level.

As SO is not suited for open design discussions, we can do that here instead. But the fact is, you are missing an abstraction.


This comment has been minimized.

anton-putau commented Nov 20, 2018

@dotnetjunkie , thanks for reply. I guess I need to make an abstraction around scope. Then I will be able to do something like

var scope = DiWrapper.GetScope()

     scope .Resolve(MyType)

Thanks for ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment