Comments (15)
Yes, I want to be responsible for scope disposal. So, you mean the startup would look like
app
.Use((ctx, next) =>
{
ctx.SetAutofacLifetimeScope(myScopeGetter());
return next();
}
.UseAutofacLifetimeScopeInjector(rootContainer)
.UseMiddlewareFromContainer<MyMiddleware>();
...and UseAutofacLifetimeScopeInjector
(RegisterAutofacLifetimeScopeInjector
, in fact) will check whether the scope exists, and if it does, will simply call next()
instead of creating/disposing its own scope?
Totally fine by me.
from autofac.owin.
Why not just insert your own middleware that creates the lifetime scope into the pipeline before the Autofac middleware runs? OWIN won't create a lifetime scope if it's already present.
You could basically copy/paste the AutofacMiddleware class, have it call your factory, and then add it to the pipeline prior to the AutofacMiddleware itself being added.
from autofac.owin.
Constants.OwinLifetimeScopeKey
is internal
, so I can't inject the scope myself (same with InjectorRegisteredKey
).
(yes, actually the minimal change that allows me to fix the problem is to simply make them public
)
from autofac.owin.
What if we added context.SetAutofacLifetimeScope(ILifetimeScope scope)
?
from autofac.owin.
This would be nice! But UseMiddlewareFromContainer
checks for injector registration, so you'd have to provide something like app.MarkInjectorAsRegistered
as well - which is not a problem by me, of course.
So the whole startup would look like this:
app
.Use((ctx, next) =>
{
ctx.SetAutofacLifetimeScope(myScopeGetter());
return next();
}
.MarkInjectorRegistered()
.UseMiddlewareFromContainer<MyMiddleware>();
from autofac.owin.
Couldn't we just add a null check here? Like, if lifetime scope isn't already set, create it; otherwise just don't do anything.
from autofac.owin.
Also, when did you want to dispose of the scope? If you set your own scope, would that mean you're responsible for disposing it? (I'm guessing so.) In that case, it'd be like "if the scope is set, just await next()
otherwise do the using/create lifetime scope thing."
from autofac.owin.
Should I draft up a pull-request for this?
from autofac.owin.
Sure, that'd rock.
from autofac.owin.
I ended up creating two pull requests, for different variants of syntax (for all I know, you can adopt both, they do not contradict each other).
from autofac.owin.
I think both enhancements are good. I'll pull them both in. You rock! Thanks!
from autofac.owin.
I have both PRs merged and semver updated to 4.1.0. Building, published to MyGet, ready to go. You mentioned you wanted to do one more look at the code to make sure it's all good, so please do and let me know if there are more changes or if it's ready.
If it's ready, I'll push it as 4.1.0 to NuGet and close this issue.
from autofac.owin.
from autofac.owin.
Done it, see #14. Sorry it took me so long, I've finally remembered what it was that I wanted to add on Saturday - an extension method to compensate for the fact that externally created lifetime scope doesn't have IOwinContext
registered.
from autofac.owin.
Pushed to NuGet as 4.1.0. Thanks again!
from autofac.owin.
Related Issues (20)
- OwinLifetimeScopeKey configurable HOT 30
- Is the dispose of the lifetime made too soon? HOT 18
- .NET Standard / .NET Core support? HOT 4
- Include the latest stable version of Microsoft.Owin (4.0.0) in dependencies HOT 6
- Autofac.Owin 4.2.0 seems to require Microsoft.Owin 3.0.0 HOT 1
- Put the registration into middlewares HOT 1
- Compatibility with Autofac v6 HOT 3
- Memory Leak Due to ThreadLocalStorage / ConcurrentBag / LifetimeScope Behavior in Owin HOT 15
- Middleware registration order is inverted during resolve HOT 4
- IAsyncDisposable HOT 1
- owin autofac middleware and controller lifetime not same one HOT 1
- 7.0.0 introduced memory leak due to async disposal issue in main Autofac HOT 10
- Nuget package cannot be installed against latest version of Autofac.
- Autofac - SingleInstance get's instantiated for every API request HOT 1
- Provide the ability to control middleware execution order in the OWIN integration HOT 3
- Move DisposeScopeOnAppDisposing from Web API OWIN integration into core OWIN integration HOT 1
- Allow DI for IAppBuilder.Run HOT 3
- Only Microsoft.Owin.Middleware HOT 2
- Middleware injection doesn't work with ACTNARS HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofac.owin.