You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
public interface IFooConcernFilter
{
// Just a marker
}
public class MyGlobalFooConcernFilter : IFooConcernFilter, IActionFilter
{
public void OnActionExecuting(...)
{
if (!IsClosestFooConcernFilter(context)
{
return;
}
}
private bool IsClosestFooConcernFilter(FilterContext context)
{
// Determine if this instance is the 'effective' foo concern policy.
for (var i = filters.Count - 1; i >= 0; i--)
{
var filter = filters[i];
if (filter is IFooConcernFilter)
{
return object.ReferenceEquals(this, filter);
}
}
Debug.Fail("The current instance should be in the list of filters.");
return false;
}
}
public class IgnoreFooConcernAttribute : Attribute, IFooConcernFilter
{
// Also just a marker
}
This gives [IgnoreFooConcern] overriding behavior. If you slap that on a controller or action, then the global filter knows to shut itself off.
We do this kind of thing frequently in the framework, and it's a non-obvious pattern. Maybe we should add some kind of infrastructure/extensions to make this easier for users to grok.
The text was updated successfully, but these errors were encountered:
I'd like to update this proposal to just put the code we described above as a protected method on filter context. Removing needs design, this is a trivial amount of work.
Code sample from #4506 (comment)
This gives
[IgnoreFooConcern]
overriding behavior. If you slap that on a controller or action, then the global filter knows to shut itself off.We do this kind of thing frequently in the framework, and it's a non-obvious pattern. Maybe we should add some kind of infrastructure/extensions to make this easier for users to grok.
The text was updated successfully, but these errors were encountered: