English 中文(简体)
Castle Windsor: UsingFactoryMethod can t instantiate with a weird error
原标题:

When I use this registration:

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

I get this exception:

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

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?

最佳回答

From the message it seems you haven t registered the IFooFactory.

Also You need to add support for the factory method. Just call this before you doing the registration:

container.AddFacility<Castle.Facilities.FactorySupport.FactorySupportFacility>();
问题回答

暂无回答




相关问题
castle IOC - resolving circular references

quick question for my MVP implementation: currently I have the code below, in which both the presenter and view are resolved via the container. Then the presenter calls View.Init to pass himself to ...

Castle Windsor auto registration

I currently have the following registration set up private static void AddFrameworkComponentsTo(IWindsorContainer container) { container.AddComponent<ITypeConverter, TypeConversionFacade>();...

Authorization and Windsor

I m trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute { private readonly IUserService _userService; public MyCustomAuth(IUserService ...

How can I override a component registered in Castle Windsor?

I m just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want ...

热门标签