IoC 配置 - 解决方案中一个 file/assembly 或每个执行程序集一个文件?

IoC configurations - one file/assembly in solution or one file per executing assembly?

我们想知道在 IoC 容器中注册类型的最佳实践是什么。

支持和反对以下原则的论点是什么:

原则一:只有一个组件my.project.DependencyInjection

原则 2:每个执行程序集一个 IoC 容器配置 class

你对此持什么立场?

提前感谢您的意见和论点

我的回答

Principle 2: A IoC container configuration class per executing assembly

Every executing assembly has their own UnityConfig.cs file
Only the needed types of this assembly are registered in the respective UnityConfig.cs file

原因是,依赖项是或应该在 运行 时注入,因此配置注入内容的责任应该在顶层 component/executable,即在 [=18] =].

同样,通过这种方法,每个项目在 DI 工具、配置等方面可能有所不同。