我正在尝试使用此页面中的代码http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx并以流畅的方式注册拦截器。但是我抛出了这个错误。我已经尝试过从 2.5 到 3.3 的 Castle Windsor 版本。所以它必须是如何设置拦截器的非常基本的东西
课程
public interface ISomething
{
Int32 Augment(Int32 input);
void DoSomething(String input);
Int32 Property { get; set; }
}
class Something : ISomething
{
public int Augment(int input) {
return input + 1;
}
public void DoSomething(string input) {
Console.WriteLine("I'm doing something: " + input);
}
public int Property { get; set; }
}
public class DumpInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation) {
Console.WriteLine("DumpInterceptorCalled on method " +
invocation.Method.Name);
invocation.Proceed();
if (invocation.Method.ReturnType == typeof(Int32)) {
invocation.ReturnValue = (Int32)invocation.ReturnValue + 1;
}
Console.WriteLine("DumpInterceptor returnvalue is " +
(invocation.ReturnValue ?? "NULL"));
}
}
设置
Console.WriteLine("Run 2 - configuration fluent");
using (WindsorContainer container = new WindsorContainer())
{
container.Register(
Component.For<IInterceptor>()
.ImplementedBy<DumpInterceptor>()
.Named("myinterceptor"));
container.Register(
Component.For<ISomething>()
.ImplementedBy<Something>()
.Interceptors(InterceptorReference.ForKey("myinterceptor")).Anywhere);
ISomething something = container.Resolve<ISomething>(); //Offending row
something.DoSomething("");
Console.WriteLine("Augment 10 returns " + something.Augment(10));
}
错误
来自程序集“DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”的类型“Castle.Proxies.ISomethingProxy”正在尝试实现无法访问的接口。