简体   繁体   中英

IoC and DI - architecture & implementation examples

I have been reading about ths approach and understand the theoretical part to a certain degree. However, I wanted to ask the community to share their real life experience of where and how they applied this technique as well how their software had benefited from doing so.

This is not discussion of which IoC Container Framework is better, but rather the approach in the whole.

Pseudo code and architectural insights are very much welcome!

Thanks.

When I first got my hands dirty with DI and IoC I found the guide on Ninject to be very helpful. It is easy to follow and does a great job of covering the necessary information. Besides the guide being great, Ninject is an excellent free implementation of dependency injection.

It's really quite simple:

Separate the code that "wires" up the objects in your application from the classes that actually "are" your application.

In other words, the fundamental architectural notion you must follow is to isolate all of the code that invokes the 'new' keyword or static methods from the code that contains business or application logic.

SEPARATE THE CODE THAT INSTANTIATES OBJECTS FROM THE CODE THAT INVOKES METHODS ON THOSE OBJECTS!!

Sorry for the yelling, but if you follow this rule you will end up with loosely coupled, easily testable code which is the point of IoC and DI-- regardless of what framework you are using. You may not even need a framework at all!

A guy named Misko Hevery has a good blog on this stuff.

Blog of Misko Hevery

The article

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM