Unity Interception in MVC

Jan 29, 2015 at 6:05 PM
Is it possible to exclude controllers from the interception process in Unity? My controllers are registered in the container and this causes a problem during the interception process because they don't have interfaces (and never will). I want to register by convention and not have to manually code every interface.

This is the error I'm getting:
Exception information: Exception type: ResolutionFailedException Exception message: Resolution of the dependency failed, type = "CSR.Presentation.Controllers.HomeController", name = "(none)". Exception occurred while: Calling constructor Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequest interceptionRequest, Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] policies, Microsoft.Practices.Unity.IUnityContainer container). Exception is: ArgumentException - Type passed must be an interface
Here's the code:
// FIRST
   container.RegisterTypes(
       AllClasses.FromLoadedAssemblies(), 
       WithMappings.FromMatchingInterface, 
       WithName.Default,
       WithLifetime.ContainerControlled,
         t => new InjectionMember[] { 
            new Interceptor<InterfaceInterceptor>(),
            new InterceptionBehavior<PolicyInjectionBehavior>()});

// SECOND
   container.AddNewExtension<Interception>();

// THIRD    
   var first = new InjectionProperty("Order", 1);
   var second = new InjectionProperty("Order", 2);

   container.Configure<Interception>()
       .AddPolicy("logging")
       .AddMatchingRule<NamespaceMatchingRule>(
            new InjectionConstructor(
            new InjectionParameter("CSR.*")))             
       .AddCallHandler<LoggingCallHandler>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(),
            first);

// Controller ==> execution doesn't reach here using interception
 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View("Index");
        }        
    }