在类库中实例化 Castle Windsor 容器时的最佳实践是什么? [英] What is best practise when instantiating a Castle Windsor container in a class library?

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

问题描述

我想知道在类库中实例化城堡 Windsor 容器的最佳位置在哪里.

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.

库类的编写方式应该允许您使用您喜欢的任何容器,或者消费者认为合适的穷人依赖注入.将库与容器耦合是一种气味.

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.

这篇关于在类库中实例化 Castle Windsor 容器时的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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