Skip to content

Instantly share code, notes, and snippets.

@sakshamsaxena
Created September 4, 2018 08:07
Show Gist options
  • Save sakshamsaxena/a49db028e9f26f25df7e4bdd731abfde to your computer and use it in GitHub Desktop.
Save sakshamsaxena/a49db028e9f26f25df7e4bdd731abfde to your computer and use it in GitHub Desktop.
using System;
namespace DemoApp
{
public class Almira
{
private Door Door { get; set; }
public void LockAlmira()
{
this.Door.LockDoor();
}
public Almira(Door door)
{
this.Door = door;
}
}
public class Door
{
public void LockDoor()
{
// Implementation
Console.Write("Locked!");
}
public Door()
{
// Constructor
}
}
class Program
{
static void Main(string[] args)
{
// Without Injector (Good way)
Almira al = new Almira(new Door());
al.LockAlmira();
// With Injector (Not so good way)
Injector ij = new Injector(); // However you create the injector (depends on language)
Almira al = ij.getInstance("Almira");
al.door.lockDoor(); // Does what the implementation tells it to
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment