Ehsan Ghanbari

Experience, DotNet, Solutions

When to use dependency injection?

In enterprise applications, when it comes to a large amount of data and different components and you are aiming for code reuse; there is a pattern named Dependency Injection to avoid tight coupling of object implementations and make the objects loosely coupled. It can be applied in any situation across the layers, but it doesn't mean that you should apply for DI everywhere!


If you don't need different implementation and different configuration Do not use Dependency injection. Although there are some related and of course older replacement patterns for DI such as abstract factory or container patterns, nut dependency injection makes the code testable as well, and it is one the biggest advantage of DI in compare to other similar patterns.


About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
Using Generic type for type casting in F#
comments powered by Disqus