我正在尝试合并Interception
使用PolicyInjectionBehavior
并得到这个错误:
异常信息:异常类型:ResolutionFailedException 异常消息:依赖解析失败,类型=“CSR.Presentation.Controllers.HomeController”,名称=“(无)”。发生异常时:调用构造函数 Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequest interceptionRequest,Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] 策略,Microsoft.Practices.Unity.IUnityContainer 容器)。例外是:ArgumentException - 传递的类型必须是接口。
如果我在注册中排除Interception
代码,它工作正常。循环遍历 中的容器Output Window
,看起来所有的注册都在那里。此外,如果我手动注册并包含Interception
代码,它也可以工作。我有很多接口,不想单独注册。这就是我正在做的事情 - 按以下顺序:
// 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");
}
}