GlobalConfiguration.Configuration.DependencyResolver with OWIN
Now that we use Owin middleware, I understand what GlobalConfiguration
should be avoided.
Previously, I used the service lookup (anti) pattern to add specific repositories to Web API check filters. For example:
public class UniqueEmployeeNameAttribute : ValidationAttribute
{
public IEmployeeRepository EmployeeRepository { get; set; }
public UniqueEmployeeNameAttribute ()
: base("Employee name must be unique.")
{
EmployeeRepository = (IEmployeeRepository)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IEmployeeRepository));
}
public override bool IsValid(object value)
{
if(value == null) { return true; }
return !EmployeeRepository.HasName(value.ToString().Trim());
}
}
When using Owin, is GlobalConfiguration.Configuration.DependencyResolver
now EmptyResolver
( System.Web.Http.Dependencies.EmptyResolver
).
How would I achieve the above when using OWIN middleware?
+4
source to share
No one has answered this question yet
Check out similar questions: