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

ExtensibleActionInvoker's filter attribute property injection is broken #311

Closed
alexmg opened this issue Jan 22, 2014 · 7 comments
Closed
Labels

Comments

@alexmg
Copy link
Member

alexmg commented Jan 22, 2014

From [email protected] on March 23, 2011 09:22:06

Because the filters passed from the base action invoker also include the controller, property injection happens on the controller itself several times as the filters are processed.

The filter attributes also included in the collection may also be singletons cached by MVC, and so it is quite likely that dependencies may be overwritten with those from a concurrently executing request.

In all this behaviour is probably too risky to reliably support.

Original issue: http://code.google.com/p/autofac/issues/detail?id=311

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From [email protected] on March 22, 2011 16:23:21

Removed property injection routine. (Breaking change.)

Status: Fixed

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From alex.meyergleaves on March 24, 2011 08:10:22

We can't go without property injection on FilterAttribute instances! Hopefully the commit below will sort it out:

Added a FilterAttributeFilterProvider implementation that performs property injection. This is supported by a new registration extension method called RegisterFilterProvider. The AutofacDependencyResolver now has a static property called Current for typed access to the current resolver. http://code.google.com/p/autofac/source/detail?r=ee052bfdad28b9974d296e7e78d19220c6c68b33

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From [email protected] on March 24, 2011 16:24:03

Sounds good. Did you have a look into the attribute caching behaviour of MVC3? From the release notes [1]:

Breaking Changes
In previous versions of ASP.NET MVC, action filters are create per request except in a few cases. This behavior was never a guaranteed behavior but merely an implementation detail and the contract for filters was to consider them stateless. In ASP.NET MVC 3, filters are cached more aggressively. Therefore, any custom action filters which improperly store instance state might be broken.

This would suggest that injecting any per-request instances into a filter attribute would lead to a race condition, but I haven't run the tests to verify it :)

Thoughts?

[1] http://www.asp.net/learn/whitepapers/mvc3-release-notes

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From [email protected] on March 24, 2011 16:25:38

(Note - I guess the alternative for injection into filter attributes would be to fall back to DependencyResolver.Current :( which is not an appealing one.)

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From alex.meyergleaves on March 24, 2011 22:52:36

Thanks Nick. You just reminded me that I forgot to pass false to the base FilterAttributeFilterProvider constructor for the cacheAttributeInstances parameter.

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From alex.meyergleaves on August 02, 2011 05:27:47

I have added documentation to the MVC 3 page on the wiki about the breaking change and how to use the new filter provider instead.

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From [email protected] on August 11, 2011 02:25:34

Great - thanks Alex.

@alexmg alexmg closed this as completed Jan 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant