4

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?

shovavnik
  • 2,878
  • 3
  • 24
  • 21

1 Answers1

10

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>();
Dmytrii Nagirniak
  • 23,696
  • 13
  • 75
  • 130
  • The IFooFactory was registered. I was missing the call to AddFacility(). Thanks! – shovavnik Dec 03 '09 at 15:07
  • 3
    Note that `FactorySupportFacility` is no longer required as of Windsor 2.5 (hurrah!) – Daniel Cassidy May 04 '11 at 17:02
  • Thanks so much for this--it was driving me crazy! I'm using a later version of Windsor for a different solution and didn't realize this is required for an older version of Windsor. – Dr. Hilarius Sep 07 '16 at 17:31