Add the actual filters interface signatures,

Add the AuthorizationFilterAttribute
This commit is contained in:
Yishai Galatzer 2014-03-03 02:24:52 -08:00
parent 75bccbae21
commit 457016a6da
7 changed files with 69 additions and 2 deletions

View File

@ -1,4 +1,6 @@
using Microsoft.AspNet.Mvc;
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MvcSample.Models;
namespace MvcSample
@ -7,6 +9,8 @@ namespace MvcSample
// TODO: Add a real filter here
[ServiceFilter(typeof(object), Order = 1)]
[ServiceFilter(typeof(string))]
[PassThrough(Order = 0)]
[PassThrough(Order = 2)]
public class FiltersController : Controller
{
private readonly User _user = new User() { Name = "User Name", Address = "Home Address" };
@ -18,4 +22,12 @@ namespace MvcSample
return View("MyView", _user);
}
}
}
public class PassThroughAttribute : AuthorizationFilterAttribute
{
public async override Task Invoke(AuthorizationFilterContext context, Func<AuthorizationFilterContext, Task> next)
{
await next(context);
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class AuthorizationFilterAttribute : Attribute, IFilter, IAuthorizationFilter
{
public abstract Task Invoke(AuthorizationFilterContext context, Func<AuthorizationFilterContext, Task> next);
public int Order { get; set; }
}
}

View File

@ -0,0 +1,8 @@
using Microsoft.AspNet.Mvc.Filters;
namespace Microsoft.AspNet.Mvc
{
public interface IActionFilter : IFilter<ActionFilterContext>
{
}
}

View File

@ -0,0 +1,8 @@
using Microsoft.AspNet.Mvc.Filters;
namespace Microsoft.AspNet.Mvc
{
public interface IActionResultFilter : IFilter<ActionResultFilterContext>
{
}
}

View File

@ -0,0 +1,8 @@
using Microsoft.AspNet.Mvc.Filters;
namespace Microsoft.AspNet.Mvc
{
public interface IAuthorizationFilter : IFilter<AuthorizationFilterContext>
{
}
}

View File

@ -0,0 +1,8 @@
using Microsoft.AspNet.Mvc.Filters;
namespace Microsoft.AspNet.Mvc
{
public interface IExceptionFilter : IFilter<ExceptionFilterContext>
{
}
}

View File

@ -0,0 +1,10 @@
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc.Filters
{
public interface IFilter<T>
{
Task Invoke(T context, Func<T, Task> next);
}
}