Created
April 17, 2012 06:40
-
-
Save ipa/2403943 to your computer and use it in GitHub Desktop.
Simple Dependency Injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DependencyInjection | |
{ | |
public interface IMotor { } | |
public class Motor : IMotor { } | |
public class Auto | |
{ | |
private IMotor motor; | |
public Auto(IMotor motor) | |
{ | |
this.motor = motor; | |
} | |
} | |
public static class Factory | |
{ | |
public static Auto CreateAuto() | |
{ | |
return new Auto(new Motor()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WithoutDependencyInjection | |
{ | |
public interface IMotor { } | |
public class Motor : IMotor { } | |
public class Auto | |
{ | |
private IMotor motor; | |
public Auto() | |
{ | |
this.motor = new Motor(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment