Autofac resolve dependency in CQRS CommandDispatcher

后端 未结 2 1727
小蘑菇
小蘑菇 2020-12-31 09:04

I\'m trying to implement a simple CQRS-application example.

This is a structure of my \"Command\" part:

public interface ICommand
{
}

//base interfa         


        
2条回答
  •  一整个雨季
    2020-12-31 09:45

    Assuming you have ConcreteCommand : IComman and ConcreteCommandHandler : ICommandHandler use RegisterType method like this:

    builder.RegisterType()
           .As>();
    

    And then inject your handler:

    private ICommandHandler concreteCommandHandler;
    

    Also look at the automatic assembly types registration Autofac abilities.

    If you'd like to resolve ICommandHandler by ICommand implementation then factory registration can help. Register Func or define special class that will resolve appropriate command handler.

提交回复
热议问题