sho*_*nik 4 castle-windsor ioc-container
当我使用此注册时:
container.Register(
Component
.For<IFooFactory>()
.ImplementedBy<FooFactory>(),
Component
.For<IFoo>()
.UsingFactoryMethod(kernel => kernel.Resolve<IFooFactory>().CreateFoo())
);
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
Castle.MicroKernel.ComponentRegistrationException:类型MyNamespace.IFoo是抽象的.因此,无法将其实例化为MyNamespace.IFoo服务的实现
我不确定问题是什么.但是堆栈跟踪显示在'DefaultComponentActivator.CreateInstance()'中,以下条件成功,然后抛出错误:
if (createProxy == false && Model.Implementation.IsAbstract)
Run Code Online (Sandbox Code Playgroud)
我需要某种代理吗?注册错了吗?
Dmy*_*iak 10
从消息来看,你似乎没有注册IFooFactory.
您还需要添加对工厂方法的支持.在进行注册之前,请先调用它:
container.AddFacility<Castle.Facilities.FactorySupport.FactorySupportFacility>();
Run Code Online (Sandbox Code Playgroud)