Skip to content

Instantly share code, notes, and snippets.

@ipa
Created April 17, 2012 06:40
Show Gist options
  • Save ipa/2403943 to your computer and use it in GitHub Desktop.
Save ipa/2403943 to your computer and use it in GitHub Desktop.
Simple Dependency Injection
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());
}
}
}
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