如何为Unity Container 5设置运行时配置(在配置文件中)(Unity.Configuration 5.11.1的问题)

问题描述 投票:0回答:1

我正在尝试使用Unity Container 5 (https://github.com/unitycontainer/unity)建立一个简单的。NET Core 3.1项目。

我已经添加了对最新的Unity Configuration 5.11.1

软件包(https://www.nuget.org/packages/Unity.Configuration/)的引用。

然后,我用最简单的配置文件创建了界面,实现和测试应用程序:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration" />
  </configSections>
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <container>
      <register
        type="Interfaces.InterfaceN, Interfaces"
        mapTo="Implementations.ImplementationN, Implementations">
      </register>
    </container>
  </unity>
</configuration>

但是我得到了System.InvalidOperationException

{“类型名称或别名Implementations.ImplementationN,实施无法解决。请检查您的配置文件并验证此类型名称。“}

我已将代码上传到GitHub。任何帮助表示赞赏。

P.S。

Visual Studio 2019 16.4.4 Enterprise,Windows 10 1909 x64 Professional

P.P.S。

。NET Framework 4.8编译的相同代码很好用-GitHub

UPDATE:

为了澄清更多-我需要一个没有任何项目引用Implementations.dll的问题,我应该能够更改特定的实现(通过更改config.json)而无需重新编译。

我正在尝试建立一个使用Unity Container 5(https://github.com/unitycontainer/unity)的简单.NET Core 3.1项目。我添加了对最新Unity配置5.11.1软件包的参考(https:// ...

c# .net dependency-injection unity-container .net-core-3.1
1个回答
0
投票

[在“测试”中添加对“实现”的引用应该可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.