创建 Castle.Windsor 拦截器时出现问题
Problems creating a Castle.Windsor interceptor
好吧,我正式失去理智了...
我正在尝试创建一个 Castle.Windsor 拦截器,但是从容器中解析一直抛出这个异常:
DependencyResolverException: An interceptor registered for
DI_Test.DatabaseService doesn't implement the IInterceptor interface
据我所知,我已经按照书上的规定做了所有事情,并且容器内容(在调试模式下)没有报告任何配置错误的服务。
容器配置:
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接口...所以有什么问题?
谢谢 :-)
有两个界面名为IInterceptor
Castle.DynamicProxy.IInterceptor
Castle.Core.Interceptor.IInterceptor
不确定它们之间有什么区别,但要使其正常工作,您必须使用第一个。
好吧,我正式失去理智了...
我正在尝试创建一个 Castle.Windsor 拦截器,但是从容器中解析一直抛出这个异常:
DependencyResolverException: An interceptor registered for
DI_Test.DatabaseService doesn't implement the IInterceptor interface
据我所知,我已经按照书上的规定做了所有事情,并且容器内容(在调试模式下)没有报告任何配置错误的服务。
容器配置:
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接口...所以有什么问题?
谢谢 :-)
有两个界面名为IInterceptor
Castle.DynamicProxy.IInterceptor
Castle.Core.Interceptor.IInterceptor
不确定它们之间有什么区别,但要使其正常工作,您必须使用第一个。