我正在尝试使用Interception
合并PolicyInjectionBehavior
并收到此错误:
异常信息: 异常类型:ResolutionFailedException 异常消息:依赖项的解析失败,键入=" CSR.Presentation.Controllers.HomeController",name ="(none)"。 发生异常时:调用构造函数 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");
}
}