IDependencyResolver 是反模式吗? [英] Is IDependencyResolver an anti-pattern?

查看:29
本文介绍了IDependencyResolver 是反模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为旧的 ASP.NET 应用程序设计一些架构更改.我设计了一些用于依赖解析的类的原型,这些类模仿了 ASP.NET MVC 的 IDependencyResolver.我不会发布,因为它的界面几乎相同,但使用其他自然语言.

I am designing some architectural changes into a legacy ASP.NET application. I prototyped some classes for dependency resolution that mimic the ASP.NET MVC's IDependencyResolver. I won't post because it is pretty much the same interface, but in other natural language.

我发现它可能被认为是服务位置,反过来通常(在某些情况下不完全)谴责它以支持依赖注入.尽管如此,我找不到任何反对使用 ASP.NET MVC 的依赖解析实现的建议.

I figured out it might be considered Service Location, which in turn is usually (not fully in some cases) condemned in favor of Dependency Injection. Nevertheless, I couldn't find any recommendation against the use of the ASP.NET MVC's dependency resolution implementation.

ASP.NET MVC 的 IDependencyResolver 是否被视为反模式?是坏事吗?

Is the ASP.NET MVC's IDependencyResolver considered an anti-pattern? Is it a bad thing?

推荐答案

如果你看一下 签名你会看到它只是一个服务定位器 有另一个名字.服务定位器是一种反模式,我认为这种关系是可传递的,所以我认为 IDependencyResolver 是一种反模式.

If you look at the signature you will see that it's just a Service Locator with another name. Service Locator is an anti-pattern and I consider the relationship transitive, so I consider IDependencyResolver an anti-pattern.

除此之外,接口也被损坏,因为它没有 Release 方法.

这篇关于IDependencyResolver 是反模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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