静态依赖注入工厂,对错?

时间:2014-04-02 05:14:57

标签: c# architecture dependency-injection inversion-of-control

当我在我正在进行的项目中对Ninject进行拍摄时,我最近遇到了一堵砖墙。

我已经经历了各种各样的问题,系统地要求我的设计和架构支持依赖注入。

  1. Is this right to inject the container/kernel to the main application presenter?

  2. How to configure Ninject to use along with NHibernate in WinForms?

  3. Conditional dependency injection binding only when property not null

  4. What did I get wrong, DI or Design, and how should I go about it?

  5. 经过几个小时,几个小时和几个小时的搜索,我看到Justin Etheredge的那篇文章,他谈到了他的静态DIFactory课程。

    我现在想知道,使用静态DI工厂是不是像魔法一样工作?

    我希望听到在实际应用中使用静态DI工厂的优缺点。

    另外,IoC和DI是一样的,还是它们非常相似,虽然有些不同?

1 个答案:

答案 0 :(得分:7)

static DI Factory is a Service LocatorService Locator is an anti-pattern,因为它会使难以推理您的代码

服务定位器的唯一优势是它略微 easier to understand than Dependency Injection。但是,DI并不难理解once you get over a few conceptual hurdles

IoC和DI之间的关系是DI is a special case of IoC