caSTLe-windsor - 温莎城堡 : UsingFactoryMethod can't instantiate with a weird error

标签 castle-windsor ioc-container

当我使用此注册时:

container.Register(
    Component
        .For<IFooFactory>()
        .ImplementedBy<FooFactory>(),
    Component
        .For<IFoo>()
        .UsingFactoryMethod(kernel => kernel.Resolve<IFooFactory>().CreateFoo())
);

我得到这个异常(exception):

Castle.MicroKernel.ComponentRegistrationException: Type MyNamespace.IFoo is abstract. As such, it is not possible to instansiate it as implementation of MyNamespace.IFoo service



我不太确定问题是什么。但是堆栈跟踪显示,在“DefaultComponentActivator.CreateInstance()”中,以下条件成功,然后抛出错误:
if (createProxy == false && Model.Implementation.IsAbstract)

我在这里需要某种代理吗?
是不是注册错了?

最佳答案

从消息看来您还没有注册 IFooFactory .

您还需要添加对工厂方法的支持。只需在进行注册之前调用它:

container.AddFacility<Castle.Facilities.FactorySupport.FactorySupportFacility>();

关于caSTLe-windsor - 温莎城堡 : UsingFactoryMethod can't instantiate with a weird error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1837893/

相关文章:

c# - StructureMap - 根据具体请求实例化接口(interface) x 实例的属性

c# - 如何在 structuremap 3 中进行 setter 注入(inject)

c# - 满足 subview 模型依赖关系

nhibernate - 这是将 NHibernate Isession 作为 PerWebRequest 处理的好解决方案吗

c# - 使用 FromAssembly 注册 CaSTLe Windsor 需要一些第 3 方引用的 dll,但不是全部

caSTLe-windsor - 在 DAL 中使用 log4net 和 CaSTLe Windsor

c# - 使用 AutoMapper.Profile 创建实例(非静态)映射器

c# - 如何通过构造委托(delegate)注入(inject)依赖项

c# - 为什么 CaSTLe Windsor 试图将我的 'Content' 和 'Scripts' 文件夹解析为 Controller ?

ioc-container - 在 Ninject 2.0 中,我如何同时拥有通用绑定(bind)和特定情况的绑定(bind)?