I want to create a filter and put it on actions that require access to the database. This filter will position the current unit of work, so I wonβt need to call it manually one or more times in one action. I'm doing it:
public class DisposeUnitOfWorkAttribute :FilterAttribute, IActionFilter { public Task<HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation) { IUnitOfWork currentUnitOfWork = UnitOfWork.Current; if (currentUnitOfWork != null) { currentUnitOfWork.Dispose(); } return null; } public bool AllowMultiple { get { return false; } } } public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new DisposeUnitOfWorkAttribute()); filters.Add(new HandleErrorAttribute()); } } [DisposeUnitOfWork] public ViewResult Index() { var user = _usersRepository.Get(x => x.Username == "jack").ToList();
I get an exception: The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.
How can i fix this?
source share