依赖注入是一个跨领域的问题吗? [英] Is the dependency injection a cross-cutting concern?
问题描述
我正在设计一个应用程序,我使用的是 n 层架构,我有:
I am designing an app and I am using a n-layer architecture, I have:
- a presentation layer
- a domain bussines layer
- a data acccess layer
- a cross-cutting layer
然后我试图将我的项目与特定的 DI 框架隔离,即创建我自己的 IContainer 接口并确保我的组件只依赖于这个接口.
Then I am trying to isolate my project from an specific DI framework, that is create my own IContainer interface and ensure that my components depends only to this interface.
那么我有两个问题.
1 - 最后一个是好习惯吗?
1 - Is this last a good practice ?
2 -(更重要的是)依赖注入是一个跨领域的问题吗?也就是可以把DI相关的组件放在横切层吗?如果答案不是哪里适合这些组件.
2 - (And the more important) Is dependency injection a cross-cutting concern ? That is can I place the DI related components in the cross-cutting layer ? If the answer is not where can fits those components.
我问这个是因为当我深入了解有关横切关注点的架构设计指南时,他们通常会提到:
I ask this because when I dive in the architecture design guides about cross-cutting concerns they usually mention:
- Security
- Validation
- Configuration handling
- Exception handling
- Loggings
- Caching
推荐答案
您是否计划更改 DI 框架?如果不是,那么抽象它们就没有意义.
Are you planning on changing DI frameworks? If not, there is no point in abstracting them.
DI 不是跨领域问题.这是一种构建对象和对象之间依赖关系的技术.
DI is not a cross cutting concern. It is a technique to structure objects and dependencies between them.
这篇关于依赖注入是一个跨领域的问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!