0

I am using Microsoft Unity (DI) container to inject my project dependencies. I am using property dependency injection (DI) in one of my custom action filter using attribute.

Example:

public class SumCheck : ActionFilterAttribute
{ 
    [Dependency]
    public TestContext _context { get; set;}

    public override void OnActionExecuting(HttpActionContext actionContext)
    {
        /* code */
    }
}

Can i resolve dependency inside OnActionExecuting? So that whenever OnActionExecuting gets called, it resolves (gets new) instance of the class that implement ITestContext?

TheKingPinMirza
  • 7,924
  • 6
  • 51
  • 81
  • 1
    Related: https://stackoverflow.com/questions/29915192/property-injection-on-attributes – Steven Jan 30 '17 at 17:36
  • 1
    See [Constructor Dependency Injection WebApi Attributes](https://stackoverflow.com/questions/28352680/constructor-dependency-injection-webapi-attributes/28365933#28365933) for an example of what @Steven is referring to. – NightOwl888 Jan 30 '17 at 18:35

0 Answers0