Created
January 17, 2015 21:30
-
-
Save devdays/f12a52135f113cbe98f7 to your computer and use it in GitHub Desktop.
Example of property 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
using System; | |
public interface IService | |
{ | |
void Serve(); | |
} | |
public class Service : IService | |
{ | |
public void Serve() | |
{ | |
Console.WriteLine("Service Called"); | |
//To Do: Some Stuff | |
} | |
} | |
public class Client | |
{ | |
private IService _service; | |
public IService Service | |
{ | |
set | |
{ | |
this._service = value; | |
} | |
} | |
public void Start() | |
{ | |
Console.WriteLine("Service Started"); | |
this._service.Serve(); | |
//To Do: Some Stuff | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Client client = new Client(); | |
client.Service = new Service(); | |
client.Start(); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment