C#和IOC传递依赖删除 [英] C# and IoC transitive dependencies removed

查看:438
本文介绍了C#和IOC传递依赖删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我用的IoC(温莎)的解决方案。
在溶液中的项目如下:

I have a solution in which I use IoC (windsor). The projects in the solution are as follows:


  1. 接口 - 保存所有我将使用接口合约
  2. IoC.Installers - 保存的所有安装程序为我的依赖关系(有参考IMPL和接口。)

  3. 的IoC - 保存保存IoC容器单个类。该类执行容器的初始化进程

  4. 控制台 - 使用国际奥委会解决依赖关系的项目(有参考接口一个IoC)

  1. Interfaces - Holds all the interface contracts I'll use.
  2. IoC.Installers - Holds all the installers for my dependencies (has reference to impl. and interfaces)
  3. IoC - Holds a singleton class that holds the IoC container. The class performs the initialization process of the container.
  4. Console - The project that uses the IoC to resolve dependencies (has reference to interfaces an IoC)

问题:由于IOC项目不直接使用IoC.Installers项目,它是从构建过程省略了控制台项目, 。因此没有安装者在初始化过程中发现的

The problem: Because the IoC project doesn't directly use the IoC.Installers project, it is omitted from the build process on the Console project, hence no installers are found during the initialization process.

解决方法:国际奥委会项目中,我补充说,直接从启动安装程序的静态构造函数该项目IoC.Installers并使用它(我做我做了实例的GetType())

The workaround: In the IoC project I added a static constructor that directly initiates an installer from the IoC.Installers project and uses it (I do a GetType() on the instance I make)

问题的解决方法:我想创建一些通用的容器支架,我可以从解决方案,以解决移动,而不需要解决我的黑客。

Problem with the workaround: I wanted to create some generic container holder that I could move from solution to solution without the need to fix my hack.

有没有更好的办法来迫使IoC.Installers的DLL被复制到bin文件夹没有破解?
的最终目的是建立一个的NuGet的面纱castlewindsor并试图找到解决方案中的所有安装程序并安装它们。

Is there a better way to force the IoC.Installers dll to be copied to the bin folder without the hack? The final aim is to create a nuget the wraps castlewindsor and tries to find all the installers in the solution and install them

我加入一个<一个HREF =https://bitbucket.org/nocgod/iocproblemdemo/src相对=nofollow>链接中,我提出能重现问题一个项目的git回购(它包含的变通以及)

I'm adding a link to a git repo in which I made a project that reproduces the problem (it contains the work around as well)

谢谢!

推荐答案

作为的Is"复制本地"传递项目引用的,你唯一的选择是

As discussed in Is "Copy Local" transitive for project references?, your only options are


  1. 添加在你的IoC容器库库的假使用; <? / LI>
  2. 添加一个生成后XCOPY一步库复制到应用程序的输出文件夹;

如果您选择#2,不知道该怎么做,有一个看的的MSBuild指南了解如何编辑的MSBuild脚本(你必须编辑<目标名称=AfterBuild/> 应用程序的元素.csproj的)。

If you choose #2 and don't know how to do it, have a look at the MSBuild guide to understand how to edit MSBuild scripts (you'll have to edit the <Target Name="AfterBuild" /> element of your application's .csproj).

这篇关于C#和IOC传递依赖删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆