好吧,我正式失去理智了......
我正在尝试创建一个 CaSTLe.Windsor 拦截器,但从容器中解析一直抛出此异常:
DependencyResolverException: An interceptor registered for
DI_Test.DatabaseService doesn't implement the IInterceptor interface
据我所知,我已经按照书中的规定完成了所有操作,并且容器内容(在 Debug模式下)没有报告任何配置错误的服务。
容器的配置:
public class ControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container
.Register(Component.For<Runner>())
.Register(Component.For<IDataDependency>()
.ImplementedBy<DatabaseService>()
.LifestyleSingleton()
.Interceptors(InterceptorReference.ForKey("wait")).Anywhere)
.Register(Component.For<WaitAndRetryInterceptor>().LifeStyle.Singleton
.Named("wait"))
;
}
}
我的拦截器:
public class WaitAndRetryInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
//throw new NotImplementedException();
}
}
我的程序:
public class Runner
{
public void Run()
{
_dataDependency.GetData();
}
public Runner(IDataDependency dataDependency)
{
_dataDependency = dataDependency;
}
private readonly IDataDependency _dataDependency;
}
public interface IDataDependency
{
void GetData();
}
public class DatabaseService : IDataDependency
{
public void GetData()
{
throw new NotImplementedException();
}
}
程序在没有配置拦截器的情况下运行完美。
我不明白为什么会抛出这个异常。拦截器明明是在实现 IInterceptor 接口(interface)……所以有什么问题?
谢谢:-)
最佳答案
有两个名为IInterceptor
的接口(interface)
CaSTLe.DynamicProxy.IInterceptor
城堡.Core.Interceptor.IInterceptor
不确定它们之间有什么区别,但要使其正常工作,您必须使用第一个。
关于c# - 创建 CaSTLe.Windsor 拦截器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48340873/