Comments (8)
As we update the tests, make sure there's no order dependency. That's actually a flaw in how ASP.NET Core ended up getting designed - instead of ordering by a property on the object in the IEnumerable
they came to depend on the order of things being resolved. If we can fix the tests in such a way that the tests pass regardless of resolution order, that'd be best.
from autofac.webapi.
I might be able to do that, but it's going to be pretty difficult because all of the filter ordering tests (which are checking everything runs in the right order and sequence for each stage) are entirely dependent upon a predictable order.
I guess I could match a manually resolved set against the executed filters for order, but personally that feels pretty messy and it's going to be quite a bit of code.
from autofac.webapi.
As an example, this test:
builder.RegisterType<TestActionFilter>()
.AsWebApiActionFilterFor<TestController>(c => c.Get())
.InstancePerRequest()
.GetMetadata(out var testFilter1Meta);
builder.RegisterType<TestActionFilter2>()
.AsWebApiActionFilterFor<TestController>(c => c.Get())
.InstancePerRequest()
.GetMetadata(out var testFilter2Meta);
// some other orchestration
Assert.Equal("TestActionFilter.OnActionExecutingAsync", order[0]);
Assert.Equal("TestActionFilter2.OnActionExecutingAsync", order[1]);
Assert.Equal("TestActionFilter2.OnActionExecutedAsync", order[2]);
Assert.Equal("TestActionFilter.OnActionExecutedAsync", order[3]);
I'm not sure how to make it non-order dependent without perhaps manually resolving the filters directly and using that to build the set of strings?
from autofac.webapi.
Let me step back a bit. If you update to Autofac 4.0.1 or later, does that change the behavior of this library? That is, under Autofac 4.0.0 you see one filter order; under 4.0.1 you see a totally different filter order?
If that's the case, it sounds like part of this may be issuing a major version that forces Autofac 4.0.1 or later because that's a breaking behavior change.
If that's not the case and the behavior of the Web API integration remains stable, then let me be slightly more clear about what I meant - I understand that there is a need for filters to run in a particular order and that tests such as the above are necessary. I'm trying to avoid fragile tests where we register a bunch of stuff, resolve those things, and just assume that the order is otherwise guaranteed. If there is a way to do that, great. If not, it's unfortunate, but it is what it is.
from autofac.webapi.
The effective filter execution order after 4.0.1 is now reversed, but the integration itself doesn't depend on the order to function correctly (in other words the behaviour of the library is still correct). It's only the tests that depend on that order.
In the wild, people who use this integration with Autofac 4.0.1+ installed would have to register their filters in the order they want them executed; anyone using a version prior to 4.0.1 would have to register them in the reverse order of how they want them executed.
I'm genuinely not sure whether upping the dependent version of Autofac in the nuspec constitutes a breaking change for the library, since no-one post 4.0.1 would see any change? It feels strange to up it by a major version when there haven't been any changes...
One other option might be to just up the version we test against, but leave the nuspec the same? That also doesn't feel quite right.
I've had a go at changing a test to not hardcode the expected resolution order, but it makes it much harder to understand what the test is doing (and this is one of the simpler ordering tests, I dread to think what the test involving the order of 40 different filters would look like):
using (var scope = container.BeginLifetimeScope("AutofacWebRequest"))
{
var resolvedFilters = scope.Resolve<IEnumerable<Meta<Lazy<IAutofacActionFilter>>>>();
resolvedOrder = resolvedFilters.Select(x => x.Value.Value.GetType().Name).ToArray();
}
await wrapper.ExecuteActionFilterAsync(
actionContext,
CancellationToken.None,
() => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));
Assert.Equal($"{resolvedOrder[0]}.OnActionExecutingAsync", order[0]);
Assert.Equal($"{resolvedOrder[1]}.OnActionExecutingAsync", order[1]);
Assert.Equal($"{resolvedOrder[1]}.OnActionExecutedAsync", order[2]);
Assert.Equal($"{resolvedOrder[0]}.OnActionExecutedAsync", order[3]);
So on balance I think I'd rather leave the order assertions in there as they currently sit.
from autofac.webapi.
The "breaking change" I'm proposing would be to update the minimum required version of Autofac from 3.5.2 to 4.0.1 to force anyone taking the update to see the new order. This is definitely one of those gray areas where semver fails to explain what to do, but since it's going to break someone and not no one it seems like that'd be a major change. I've taking major updates to Newtonsoft.Json and never seen any problems, but that doesn't mean no one got broken, right? :)
If it's too hard to change, don't worry about it. We can just fix the tests again if needed.
from autofac.webapi.
Understood; I'll up the nuspec version to 5.0 of this integration (which conveniently but entirely accidentally lines us up with the next Autofac release).
from autofac.webapi.
Fixed
from autofac.webapi.
Related Issues (20)
- Dependency Issue on latest version on nuget HOT 2
- Bad async/await implementation causing loss of execution context. HOT 9
- Help - Autofac.WebApi2 Global Action FIlters Parameters injection failed HOT 1
- Please, consider to release the 4.2.0 version of the Nuget package HOT 2
- Could not load file or assembly 'Autofac, Version=3.0.0.0' when using Autofac.WebApi 3.1.0 HOT 3
- What should I do tp set the value of ControllerContext property after GetService method? HOT 3
- Cannot get Autofac to work with Web API HOT 2
- Performance: Use TryGetValue instead of ContainsKey() + indexer sequence HOT 3
- Registration of filters on base classes no longer work HOT 3
- Autofac filters for specific 'async' action in a controller not working HOT 1
- Injecting a registered named service is not working as expected. HOT 1
- Autofac 5 was pushed to Github a few days ago along with MVC 5 but the current version of WebApi2 is not usable with it HOT 1
- Compatibility with Autofac v6 HOT 1
- Web requests never return when using Autofac, unless pre-resolved HOT 2
- HttpRequestMessage is disposed after the filters are resolved HOT 7
- Override Exception Filters executed last instead of first HOT 3
- Filters at controller scope not ran when action scoped filters exist. HOT 3
- Change CallContext to AsyncLocal HOT 5
- Self-hosted WebApi Custom Authorization Filter/Attribute using IAutofacAuthorizationFilter HOT 4
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.webapi.