1
我有以下情形:城堡溫莎代理抽象類與接口
public interface IFoo
{
void Foo1();
void Foo2();
}
public abstract class Foo : IFoo
{
public void Foo1() { }
public abstract void Foo2();
}
我想註冊的IFoo服務,由富執行,但攔截處理對非實現抽象成員通話。所以,我可以這樣做:
container.Register(Component.For<IFoo>()
.ImplementedBy<Foo>().Interceptors<MyInterceptor>());
但我得到下面的異常試圖激活我的組件:
"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)
我發現了以下工作順利....
Component.For<Foo>().Forward<IFoo>().Interceptors<MyInterceptor>()
但後來我的截擊結束看到富,不IFoo的作爲在的TargetType截取時間......這不是我想要的。
有關如何完成此任務的任何建議?
謝謝。
如果我做以上(基本上specifiying美孚作爲一個前鋒),富的實施似乎並沒有在那裏得到的...所以當我打電話foo2的(),然後我的攔截試圖調用invocation.Proceed,我得到:這是一個DynamicProxy2錯誤:攔截器試圖'繼續'方法'Void Foo2()'沒有目標。 – Jeff 2011-05-23 14:05:20
沒錯。這提醒我,這裏的排序可能很重要。我記得解決這個問題,以便順序無關緊要,但也許它只是主幹。無論如何 - 如果您在註冊時交換訂單,您應該沒問題。 – 2011-05-23 21:21:54
因此Component.For?這不會阻止服務類型成爲IFoo嗎?或者我誤解了? –
Jeff
2011-05-23 22:16:05