Using Autofac Conventions Based on Configuration Values

I have a command / handler based architecture app . I have the following interface:

public interface ICommandHandler<TCommand>
{
    void Handle(TCommand command);
}

There are many non-general implementations of this interface. These implementations are wrapped by common decorators, such as:

public class ProfilingCommandHandlerDecorator<TCommand> : ICommandHandler<TCommand>
{
    private readonly ICommandHandler<TCommand> decoratee;

    public ProfilingCommandHandlerDecorator(ICommandHandler<TCommand> decoratee)
    {
        this.decoratee = decoratee;
    }

    public void Handle(TCommand command)
    {
        // do profiling here
        this.decoratee.Handle(command);
        // aaand here.
    }
}

However, some of these expanders should be applied conditionally based on the flag in the configuration file. I found this answer , which conditionally refers to the use of non-standard decorators; not about the general decorator. How can we achieve this with common decorators in Autofac?

+2
source share
1

IRegistrationSource. Autofac OpenGenericDecoratorRegistrationSource, .

0

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


All Articles