本文介绍了温莎城堡:UsingFactoryMethod无法实例化,出现奇怪的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用此注册时:
container.Register(
Component
.For<IFooFactory>()
.ImplementedBy<FooFactory>(),
Component
.For<IFoo>()
.UsingFactoryMethod(kernel => kernel.Resolve<IFooFactory>().CreateFoo())
);
我收到此异常:
我不确定问题是什么。但是堆栈跟踪显示,在'DefaultComponentActivator.CreateInstance()'中,以下条件成功,然后引发错误:
I'm not really sure what the problem is. But the stack trace shows that in 'DefaultComponentActivator.CreateInstance()', the following condition succeeds and then the error is thrown:
if (createProxy == false && Model.Implementation.IsAbstract)
我是否需要代理这里的某种?
注册错误吗?
Do I need a proxy of some sort here?Is the registration wrong?
推荐答案
从消息看来,您尚未注册 IFooFactory
。
From the message it seems you haven't registered the IFooFactory
.
还需要添加对factory方法的支持。只需在注册之前调用此命令即可。
Also You need to add support for the factory method. Just call this before you doing the registration:
container.AddFacility<Castle.Facilities.FactorySupport.FactorySupportFacility>();
这篇关于温莎城堡:UsingFactoryMethod无法实例化,出现奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!