Question

I am using the TypedFactoryFacility in Castle Windsor to allow me to use the interface-factory dependency injection.

I am having issues with the automatic delegate-factory injecting Func into automatically resolved components when these are not required (should be Null).

I would like to keep the TypedFactoryFacility, but remove the DelegateFactory, as per this question:

Can Windsor's TypedFactoryFacility's implicit delegate factory registration be disabled?

Unfortunately there is now no way to remove components from Castle Windsor (version 3).

Can someone suggest either a way to remove the DelegateFactory or somehow disable it so it does not inject Func into my services that can not be resolved (why is it even injecting Func that it does not know how to handle anyway??)

Was it helpful?

Solution

I was unable to find how to remove a component (this should be added back in).

The best way I could find to disable the DelegateFactory was stop using the TypedFactoryFacility class to setup the Typed Factories and use the code from the Init function inside it, minus the delegate factory methods.

As so:

// Stop using AddFacility
//container.AddFacility<TypedFactoryFacility>();

// Initialise the TypedFactoryFacility manually, leaving out the DelegateFactory components.
container.Kernel.Register(new IRegistration[] {
   Component.For<TypedFactoryInterceptor>().NamedAutomatically(TypedFactoryFacility.InterceptorKey),
   // Disable DelegateFactory
   // Component.For<ILazyComponentLoader>().ImplementedBy<DelegateFactory>().NamedAutomatically(TypedFactoryFacility.DelegateFactoryKey),
   Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultTypedFactoryComponentSelector>().NamedAutomatically("Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector"),
   // Disable DelegateFactory
   // Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultDelegateComponentSelector>().NamedAutomatically(TypedFactoryFacility.DefaultDelegateSelectorKey)
});
container.Kernel.ComponentModelBuilder.AddContributor(new TypedFactoryCachingInspector());

I had to use magic string "Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector" DefaultInterfaceSelectorKey is an internal field.

Now you can use interface-factories, without delegate-factories messing everything up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top