title: Setter Injection with Unity for ActionFilter
body: <p>Hi I use <a href="http://msdn.microsoft.com/en-us/library/ff647202" rel="nofollow noreferrer">MS Unity Container</a> with my MVC 3 application.</p>
  
  <p>I want to use setter injection to inject a dependency for Action filter. I have an action filter which I am registering in global.asax and this action Filter calls a repository class to load some data. I want to inject concrete class using DI. It can be very <a href="http://lostechies.com/jimmybogard/2010/05/03/dependency-injection-in-asp-net-mvc-filters/" rel="nofollow noreferrer">easily achieved with StructureMap</a>. But somehow I can't get it working with Unity. I have tried all solutions from this <a href="https://stackoverflow.com/questions/515028/setter-property-injection-in-unity-without-attributes">link</a>.</p>
  
  <p>Here is my code:</p>
  
  <p>MyActionFilter.cs</p>
  
  <pre><code>public class GlobalViewBagActionFilter : ActionFilterAttribute
  {
      public IUserRepo UserRepo { get; set; }
  
      public override void OnResultExecuting(ResultExecutingContext filterContext)
      {
          var testVal = UserRepo.LoadData();
      }
  }
  </code></pre>
  
  <p>Registering Action Filter in Global.asax.cs</p>
  
  <pre><code>private static void RegisterGlobalFilters(GlobalFilterCollection filters)
      {
          filters.Add(new GlobalViewBagActionFilter());
      }
  </code></pre>
  
  <p>calling the above method on Appliation_Start to register </p>
  
  <pre><code>RegisterGlobalFilters(GlobalFilters.Filters);
  </code></pre>
  
  <p>I have tried many possible code block for registering the class but nothing worked. Either I would get an exception or on the action filter, UserRepo property would be null.</p>
  
  <p>Any pointers on how do i get it working?</p>