Comments (4)
The Implementations
property returns the set of implementations of a service in the same order as v4; the reversal you link to in core Autofac was actually just a re-implementation of a reversal which existed in v4 of Autofac.
Looking in to the actual implementation of how the set of middleware is determined indicates that the library depends on the order of the Registrations
property, not Implementations
:
internal static IEnumerable<Type> GenerateAllAutofacMiddleware(IComponentContext container)
{
return container.ComponentRegistry.Registrations.SelectMany(r => r.Services)
.OfType<TypedService>()
.Where(s => IsMiddlewareButNotAutofac(s.ServiceType))
.Select(service => typeof(AutofacMiddleware<>).MakeGenericType(service.ServiceType))
.ToArray();
}
It doesn't even attempt to use our IEnumerable
support. Prior to v5, the Registrations
property was a List<T>
of component registrations, hence a dependable order. In v5, the backing type for that set was changed to a ConcurrentBag
to reduce locking, but the order of that set is then basically "undefined". Even stating "Reverse the order of your registrations" isn't perfect advice, because they could come out in any order.
Other code across the Autofac extensions expressly avoids depending on this order, preferring instead the predictable and documented order of components registered for a given service, when resolving via IEnumerable<T>
.
The simplest fix here may be to apply an OrderBy
line that retrieves the ServiceRegistration
details, and through that the RegistrationOrder
value to sort by. That does give a predictable order at least.
internal static IEnumerable<Type> GenerateAllAutofacMiddleware(IComponentContext container)
{
return container.ComponentRegistry.Registrations.SelectMany(r => r.Services)
.OfType<TypedService>()
.Where(s => IsMiddlewareButNotAutofac(s.ServiceType))
.OrderBy(s => container.ComponentRegistry.TryGetServiceRegistration(s, out var reg) ? reg.GetRegistrationOrder() : 0)
.Select(service => typeof(AutofacMiddleware<>).MakeGenericType(service.ServiceType))
.ToArray();
}
It's not a great fix, and if this was a more 'current' integration library, I'd look to do a cleaner fix by switching to registering middleware differently under a single Service
or something. But for Owin this may be sufficient.
from autofac.owin.
I think the OrderBy
line is probably a "good enough" fix. I'm not super interested in spending a lot of time here given it appears no one even noticed this for almost two years (the length of time it's been since we updated Autofac internals to support .NET core ordering, around v5).
from autofac.owin.
Forgot about this one. Sigh. I'll add a PR for this after #30 goes through.
from autofac.owin.
I'll put this in, just approved #30, so will merge that and apply this fix.
from autofac.owin.
Related Issues (20)
- OwinLifetimeScopeKey configurable HOT 30
- External creation of ILifetimeScope HOT 15
- 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
- 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.