Skip to content

Instantly share code, notes, and snippets.

@thedom85
Last active August 29, 2015 14:18
Show Gist options
  • Save thedom85/7c8e3d82cf4c25808704 to your computer and use it in GitHub Desktop.
Save thedom85/7c8e3d82cf4c25808704 to your computer and use it in GitHub Desktop.
CSharp_Pattern_Dependency_Injection_Create
//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