如何将统一配置部分分成几个文件?

发布于 2024-11-16 19:45:35 字数 227 浏览 7 评论 0原文

在我的项目中,有一些通用包,它的依赖项由在 unity.config 文件中定义的 UnityContainer 解析。 还有另一个自定义包,我想在单独的 CustomUnity.config 文件中拥有自己的自定义 UnityContainer。

在运行时,我希望这两个文件都被加载,当我获得 Unity 部分时,我希望它包含两个 UnityContainer。

我怎样才能实现它?

谢谢!

In my project there is some common package which gets its dependencies resolved by the UnityContainer which is defined in unity.config file.
There is another custom package which I want to have its own custom UnityContainer in a seperated CustomUnity.config file.

In runtime I want both files to be loaded and when I get the unity section, I want it to contain both UnityContainers.

How can i achieve it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呢古 2024-11-23 19:45:35

UnityContainer.LoadConfiguration 方法可以在同一容器上多次调用。每次它都会加载该配置部分中的所有内容,但它不会删除容器中先前的内容 - 它是附加的。如果存在冲突(两个部分都配置相同的类型),则最后一个获胜。

因此,方法是使用 ConfigurationManager API 加载两个单独的 UnityConfigurationSections,然后调用 LoadConfiguration 两次,每个配置部分调用一次。这应该就是你所要做的一切。

The UnityContainer.LoadConfiguration method can be called multiple times on the same container. Each time it loads whatever's in that configuration section, but it doesn't remove what was previously in the container - it's additive. If there's a conflict (both sections configure the same type) then last one in wins.

So, the approach would be to use the ConfigurationManager APIs to load your two separate UnityConfigurationSections, and then call LoadConfiguration twice, once for each configuration section. That should be all you have to do.

忘年祭陌 2024-11-23 19:45:35

我编写了一个库,可让您在模块中编写 ioc 容器配置。它支持统一,但您必须在代码中配置容器,而不是使用文件。我不知道是否能解决您的问题,但您可以在 bootstrapper.codeplex.com 上查看

I wrote a library that lets you write your ioc container configuration in modules. It supports unity but you will have to configure your container in codes instead of using the files. I don't know if will solve your problem, but you can check it out at bootstrapper.codeplex.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文