开发者

Real website/-application use cases where dependency injection was useful (excluding unit testing/mocks)?

In what concrete web project(s) (you don't have to name them by name of course), specifically what part of the web-application/website, that you have worked on, has dependency injection proven to be a good choice. Can you give concrete examples where you actually substituted one com开发者_开发百科ponent for another with DI during the life span of the project, excluding cases for mock/unit testing?


Dependency injection is not about substituting components. It's about decoupling code, it helps keep cohesion high and coupling low.

Substituting components is just one (and not too common in my experience) of the things you can do with DI.

If you really want examples of substituting components:

  • I had a faxing service that connected to a remote Windows Fax Server to send faxes. I replaced that with a service that sends faxes via j2.com instead.
  • I had a service to search "stuff". This service was implemented first against a RDBMS, later was replaced with a search against a Solr instance.
  • The application cache was abstracted as a component. First it was implemented using the ASP.NET builtin cache, later it was replaced using memcached.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜