// Comand Handler interface
public interface ICommandHandler<in T> where T : ICommand
{
Task<CommandResult> Execute(T command);
}
// Command Interface
public interface ICommand
{
public string MyProperty { get; set; }
}
// MyCommand class
public class MyCommand : ICommand
{
public public string MyProperty { get; set; }
}
// MyCommand handle
public class MyCommandHandler : ICommandHandler<MyCommand>
{
public async Task<CommandResult> Execute(MyCommand command)
{
}
}
// Command Factory
public class CommandHandlerFactory
{
private readonly ICommandHandler<MyCommand> _myCommand;
public CommandHandlerFactory(ICommandHandler<MyCommand> myCommand)
{
_myCommand = myCommand;
}
public ICommandHandler<?> Build(MyEnum myEnum)
{
var builder = new Dictionary<MyEnum, ICommandHandler<?>>
{
{ LineOfBusiMyEnumessEnum.MyEnumValue, _myCommand }
};
return builder[myEnum];
}
}