【发布时间】:2020-04-24 01:49:22
【问题描述】:
我正在将旧的 .net v 4.5.1 项目移植到最新的 .net 核心。 对于旧的 .net 框架项目中的依赖注入,使用 Unity 容器,其中所有服务注册都存储在 web.config 中。
全球.asax:
UnityConfigurationSection section
= (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Configure(container, "unityContainer");
web.config:
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container name="primaryUnityContainer">
<register type="ILogger" mapTo="Log4NetLogger"/>
问题是:.net core 3 在应用程序外部的配置文件中配置服务的最佳方式是什么,例如在 appsettings.json 中,以便可以为不同的环境注册不同的实现。
可以扩展内置容器还是最好使用具有此功能的第三方?
还有哪些其他方法可以针对特定环境进行服务实现?
【问题讨论】:
标签: .net asp.net-core .net-core dependency-injection unity-container