Windsor Castle permits zero or more implementations

(A slightly simplified scenario to highlight a specific problem).

I am trying to use Castle Windsor to solve a component that has a constructor with a single parameter, which is an array of the service interface:

public class TestClass<T>
{
    public TestClass(IService<T>[] services)
    {
        ...
    }
}

The Windsor container is configured to use an ArrayResolver array:

container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

It all works fine, and one or more services are introduced for different instances of T.

However, for some T there are no realizations IService<T>. The goal would be for the constructor to be called with an array of zero length.

The problem is that if there are no specific IService implementations for a given T, how can I register an IService definition without an implementation, so that the container knows the type?

I use:

container.Register(
    Classes.FromAssembly(Assembly.GetExecutingAssembly())
        .BasedOn<IService<>>()
        .WithService.FirstInterface());

, , , "" IService.

- IService T, "" , . ( ...).

+4
1

, ...

ArrayResolver - , :

container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, true));

.

+4

Source: https://habr.com/ru/post/1665641/


All Articles