Hello
Probably this is a duplicate... but I will describe my problem anyway.
Lets say I have classes:
public abstract class Foo
{
public virtual void DoSomething()
{
Console.WriteLine("Doing something base");
}
}
public class Bar : Foo
{
public override void DoSomething()
{
Console.WriteLine("Doing something");
base.DoSomething();
}
}
and interceptor:
public class MyAspect : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("Method is intercepted...");
invocation.Proceed();
}
}
public class MyInterceptorSelector : IModelInterceptorsSelector
{
public bool HasInterceptors(ComponentModel model)
{
return typeof(MyAspect) != model.Implementation &&
model.Implementation.Namespace.StartsWith("Dp2");
}
public InterceptorReference[] SelectInterceptors(ComponentModel
model, InterceptorReference[] interceptors)
{
var interceptorss = interceptors.ToList();
interceptorss.Add(InterceptorReference.ForType<MyAspect>());
return interceptorss.ToArray();
}
}
and registration:
public class Bootstrapper
{
public Bootstrapper(IWindsorContainer container)
{
Container = container;
}
public IWindsorContainer Container { get; private set; }
public void Run()
{
Container.Register(Component.For<MyAspect>());
Container.Kernel.ProxyFactory.AddInterceptorSelector(new
MyInterceptorSelector());
Container.Register(Component.For<Foo>().ImplementedBy<Bar>());
}
}
in test:
[TestFixture]
public class UnitTest1
{
[Test]
public void TestMethod1()
{
var bts = new Bootstrapper(new WindsorContainer());
bts.Run();
var bar = bts.Container.Resolve<Foo>();
bar.DoSomething();
}
}
output is:
Method is intercepted...
Doing something
Doing something base
ergo interceptor hasn't been called on base method execution.
Is there a way to make this work?
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.