What is the good analogy to understanding IoC and DI?
"post-less" itemprop = "text">
If you take a classic example of the car, you buy a regular car Go through the process and the manufacturer gives you the wheel:
public squares fifteen {public zero roll () {Console.WriteLine ("nice smooth family ride ..." ); }} Public class car {Fifthansa wheels = newfnts (;); Public car () {} Public Zero Drive () {wheels.Roll; }} then:
car myCar = new car (); MyCar.Drive () // uses stock wheels Or can you locate a custom car builder who can specify which type of wheel you want to use for your car They want to use, as long as they are in conformity with the specifications of a wheel:
Public interface IWheel {zero roll (); } Public Class Twenty: IWheel {Public Zero Roll () {Console.WriteLine ("Rough Ridin" ...};} Public Class Car {IWheel _wheels; Public Car (IWheel Wheels) {_wheels = Wheels;} Public Zero Drive ( } Mycar = new car (new immersion); myCar.Drive (););} then:
; // You use injection wheels But now you can inject whatever wheel you want. Keep in mind that it is only one type of dependency injection (Manufacturer injection), but it serves as one of the simplest example.