在类库实例化一个温莎城堡容器时,什么是最好的做法? [英] What is best practise when instantiating a Castle Windsor container in a class library?

查看:175
本文介绍了在类库实例化一个温莎城堡容器时,什么是最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道最好的地方来实例化温莎城堡容器是一个类库。

I am wondering where the best place to instantiate the castle Windsor container is in a class library.

我应该只是做它在我的类的构造函数使用或者是有一个单一的入口点,我不知道的组件?

Should I simply do it in the constructor of the class I am using or is there a single entry point for assemblies that I am unaware of?

感谢。

推荐答案

注入对象图的结构是完全依赖于实际使用它的应用程序的需要。使用容器的一点是要能够在运行时配置的依赖 - 库不知道它是如何将要使用什么

The configuration of an injected object graph is entirely dependent on the needs of the application that actually uses it. The point of using the container is to be able to configure dependencies at runtime - a library doesn't know anything about how it's going to be used.

库班应该是书面的方式,可以让你在消费者看到适合使用任何你喜欢的容器中,或贫man's的依赖注入。耦合的库的容器是一个味道。

Library classes should be written in a way that allows you to use any container you like, or poor-man's-dependency-injection as the consumer sees fit. Coupling a library to a container is a smell.

这篇关于在类库实例化一个温莎城堡容器时,什么是最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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