Is IDependencyResolver an anti-pattern?

◇◆丶佛笑我妖孽 提交于 2019-11-26 10:55:49

问题


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.

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.

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


回答1:


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.

Apart from that, the interface is also broken because it has no Release method.




回答2:


I don't believe so... You can inject any IoC you want into ASP.NET MVC, which seems like a pretty good pattern to me.

Here's a blog post about injecting Unity into ASP.NET MVC 3.



来源:https://stackoverflow.com/questions/5653783/is-idependencyresolver-an-anti-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!