.Net C#依赖注入可解析相同类型的ICommands

我有一个在构造函数参数中包含许多ICommands的类。

var classWithManyCommands = 
            new ClassWithManyCommands(new AddItemsCommand(new StringService()),new AddItemsCommand(new IntegerService()),...);


public ClassWithManyCommands(
  ICommand command1,ICommand command2,ICommand command3,ICommand command___,ICommand command50,)
{
  _command1 = command1;
   ...
}

当我将 ClassWithManyCommands 和命令注册到DependencyInjection容器(在我的情况下为AutoFac)中时,它将无法自动解决。

将ICommands存储在像 AddCommandsContainer 这样的对象中,这将是一个很好的过程吗?我知道这不是IoC。

var addCommandsContainer = new AddCommandsContainer(new StringService(),new IntegerService());
var classWithManyCommands = new ClassWithManyCommands(addCommandsContainer);

public ClassWithManyCommands(AddCommandsContainer addCommandsContainer)
{
  _command1 = addCommandsContainer.command1;
  ...
}
jialinjl 回答:.Net C#依赖注入可解析相同类型的ICommands

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2422770.html

大家都在问