I have the following scenario:
public interface IFoo
{
void Foo1();
void Foo2();
}
public abstract class Foo : IFoo
{
public void Foo1() { }
public abstract void Foo2();
}
I want to register a service for IFoo, implemented by Foo, but with an interceptor to handle calls to the non-implemented abstract members. So, I can do:
container.Register(Component.For<IFoo>()
.ImplementedBy<Foo>().Interceptors<MyInterceptor>());
But I get the following exception trying to activate my component:
"Instances of abstract classes cannot be created."
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, Object[] arguments, Type[] signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context)
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveServiceDependency(CreationContext context, ComponentModel model, DependencyModel dependency)
I've noticed that the following works successfully....
Component.For<Foo>().Forward<IFoo>().Interceptors<MyInterceptor>()
but then my interceptor ends up seeing Foo, not IFoo as the TargetType at interception time...which is not what I want.
Any suggestions on how to accomplish this?
Thanks.