0
我有一个IModelInterceptorsSelector
一个WindsorContainer
。除了没有实现的组件外(例如,所有行为都由IInterceptor
动态处理),它都可以正常工作。温莎城堡为代理接口,而目标
如果我试图解决一个component接口而已,我得到:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException occurred
Message=Could not find a public constructor for type ConsoleApplication1.IInterfaceOnlyService. Windsor can not instantiate types that don't expose public constructors. To expose the type as a service add public constructor, or use custom component activator.
Source=Castle.Windsor
StackTrace:
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.FastCreateInstance(Type implType, Object[] arguments, Type[] signature)
但是如果我手动指定在注册时的拦截器,它工作得很好。这是温莎的错误还是我做错了什么?
的代码重现相当简单:
var container = new WindsorContainer();
container.Kernel.ProxyFactory.AddInterceptorSelector(new Selector());
container.Register(Component.For<TestInterceptor>());
container.Register(Component.For<IInterfaceOnlyService>()); // this doesn't work
// container.Register(Component.For<IInterfaceOnlyService>().Interceptors<TestInterceptor>()); // this works
var i = container.Resolve<IInterfaceOnlyService>();
public class Selector : IModelInterceptorsSelector
{
public bool HasInterceptors(ComponentModel model)
{
return model.Service != typeof (TestInterceptor);
}
public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors)
{
return new[] { InterceptorReference.ForType<TestInterceptor>() };
}
}
感谢。
不知道你可以这样做与温莎和误读的问题,因为这一点。删除答案。 – 2010-10-31 21:24:10