I can't get dependency injection working with a custom ActionFilterAttribute class using the Unity bootstrapper for ASP.NET Web API nuget package.
I've registered the type in UnityConfig and I'm using it elsewhere (using constructor injection there though) and it works fine.
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<ISettingService, SettingService>();
...
}
The code is being called successfully, however the instantiated object (settingService) is null.
public class APIKeyValidationAttribute : ActionFilterAttribute
{
[Dependency]
public ISettingService settingService { get; set; }
public override void OnActionExecuting(HttpActionContext actionContext)
{
...
if (settingService == null)
{
throw new Exception("settingService is null");
}
...
}
What do I need to do to get this working? I've been searching for a long time and can only find examples for MVC or for Web API with different dependency injectors.