c# - .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;
...
}
当我在我的 DependencyInjection 容器(在我的情况下为 AutoFac)中注册ClassWithManyCommands和命令时,它无法自动解决它。
ICommands
将它们存储在像AddCommandsContainer这样创建它们的对象中会是一个好的过程吗?这不是国际奥委会,我知道。
var addCommandsContainer = new AddCommandsContainer(new StringService(), new IntegerService());
var classWithManyCommands = new ClassWithManyCommands(addCommandsContainer);
public ClassWithManyCommands(AddCommandsContainer addCommandsContainer)
{
_command1 = addCommandsContainer.command1;
...
}
解决方案
推荐阅读
- git - PCF 配置服务器不刷新属性
- mysql - 2021年Mac上的Mysql odbc excel
- assembly - 为什么 GNU 为内存写入添加偏移量?
- r - 将是/否 CSV 列更改为 R 中的数字数据
- java - JavaFX Eclipse 建议导入不存在
- python - 仅使用 coverage.py 计算测试覆盖率以使用 anybadge 创建 gitlab 徽章
- maven - 为什么在 Maven 项目中强制执行 apache-rat-plugin?
- jquery - jQuery:数据未加载:ERR_FAILED / ERR_HTTP2_PROTOCOL_ERROR / ERR_CONNECTION_CLOSED
- postman - Postman 客户端:无法设置请求正文(显示忙碌指示符)
- c - C指针和int之间的int乘法问题