跨Visual Studio项目的IOC? [英] IOC across visual studio projects?

查看:66
本文介绍了跨Visual Studio项目的IOC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将IOC和DI改装(我知道这个主意不好,但是总比没有好,要迟到了)。



代码库由大约30个项目组成,每个项目中都有类,这些类对外界几乎没有可见性。作为IOC的新手,我正在尝试在重新编写代码时使用最佳实践,而且似乎最好不要将IOC容器传递过来或使其静态化,因此,我尝试通过构造函数注入来完成所有工作。



但是,这是我的问题,我不得不在整个项目(例如,物理.csproj文件)中公开大量的类。我之所以必须这样做是因为我的配置模块(我正在使用Ninject,但这是一个IOC不可知的问题)需要了解任何项目中任何类的所有内容,以便能够解决依赖关系。 / p>

我错过了重要的东西吗?如果我所有的类都是基于接口的,是否应该公开?我可以为我的每个csproj边界创建一个IOC容器,并为我做注入吗?



Ta

解决方案

您是否可以在每个项目中都不编写配置模块,而仅将其公开?然后使用所有模块而不是单个模块配置ninject。


I'm trying to retro-fit (bad idea I know, but better late than never) IOC and DI into an existing solution.

The code base is made of up about 30 projects, each which have classes in them which have little or no visibility to the outside world. Being relatively new to the IOC thing I'm trying to use best practise when reworking the code, and it seems best not to pass the IOC container around or make it static, hence I'm trying to do everything via constructor injection.

However, and here comes my question, I am having to make an awful lot of the classes public across projects (i.e. physical .csproj files). I'm having to do this because my 'configuration module' (i'm using Ninject, but this is an IOC agnostic question) needs to know about everything in any class in any project in order to be able to resolve the dependencies.

Have I missed something significant? Are all my classes supposed to be public if they are based on an interface? Can I somehow create an IOC container for each of my csproj boundaries and have that do the injection for me?

Ta

解决方案

Could you not write a configuration module inside each project, and only make that public? Then configure ninject with all of the modules instead of a single one...

这篇关于跨Visual Studio项目的IOC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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