问:使用依赖注入的内部操作类库的最佳实践? [英] What are the best practices for class libraries using dependency injection for internal operations?

查看:110
本文介绍了问:使用依赖注入的内部操作类库的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该小心建立一个类库复杂时,足够使用内部依赖注入?

What should I be careful about when building a class library complex enough to use internal dependency injection?

假设它会使用温莎城堡(作为一个例子),这将是因为该图书馆将通过简单的控制台应用程序(不带DI)中使用,使用相同的容器(温莎城堡)使用不同的容器Web表单和Web应用程序的最佳场所/的方法来配置容器,(NInject )?

Assuming that it will use Castle Windsor (as an example), what would be the best place/method to configure the container, given that the library will be used by simple console application (with no DI), web forms using the same container (Castle Windsor), and web apps using a different container (NInject)?

推荐答案

我会用的 Facade模式的位置:在图书馆,暴露在一个公开的类,它的容器初始化的公共方法(如一个简单的初始化()) ,并使用温莎城堡仅在内部库中,从而使该库客户甚至不知道你正在使用它。

I would use the facade pattern here: in the library, expose a public method on a public class that does the container initialization (such as a simple Initialize()), and use Castle Windsor only internally within the library, so that the library clients don't even know that you are using it.

这篇关于问:使用依赖注入的内部操作类库的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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