Last active
August 29, 2015 14:18
-
-
Save thedom85/7c8e3d82cf4c25808704 to your computer and use it in GitHub Desktop.
CSharp_Pattern_Dependency_Injection_Create
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
//LINQPad | |
//CSharp_Pattern_Dependency_Injection_Create.cs | |
void Main() | |
{ | |
Client client = new Client(new Service()); | |
client.Start(); | |
} | |
public interface IService | |
{ | |
void Serve(); | |
} | |
public class Service : IService | |
{ | |
public void Serve() | |
{ | |
Console.WriteLine("## Service Called ##"); | |
} | |
} | |
public class Client | |
{ | |
private IService _service; | |
public Client(IService service) | |
{ | |
this._service = service; | |
} | |
public void Start() | |
{ | |
Console.WriteLine("## Service Started ## "); | |
this._service.Serve(); | |
} | |
} | |
//Inspired by : http://en.wikipedia.org/wiki/Dependency_injection | |
//Inspired by : http://www.dotnet-tricks.com/Tutorial/dependencyinjection/67LX120413-Implementation-of-Dependency-Injection-Pattern-in-C | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment