Skip to content
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

SimpleInjector sample needs scoping example #9

Closed
decoy opened this issue Feb 24, 2017 · 1 comment
Closed

SimpleInjector sample needs scoping example #9

decoy opened this issue Feb 24, 2017 · 1 comment

Comments

@decoy
Copy link
Owner

decoy commented Feb 24, 2017

Simple injector has a bunch of packages for automatically creating scopes for various frameworks, but it's not difficult to setup manually.

Container Setup:

var container = new Container();
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

Creating the scope per request:

app.Use(async (context, next) =>
{
    using (AsyncScopedLifestyle.BeginScope(container))
    {
        await next();
    }
});

Registering a service for scoped creation:

container.Register<IRepository, Repository>(Lifestyle.Scoped);

Also, could it make sense to create a PingPongr.SimpleInjector package to handle all of this? (With stronger dependencies on aspcore to do registrations?)

@decoy
Copy link
Owner Author

decoy commented Feb 28, 2017

SimpleInjector already has a package for this:
https://simpleinjector.readthedocs.io/en/latest/aspnetintegration.html

@decoy decoy closed this as completed Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant