Exemplo n.º 1
0
        static void Main(string[] args)
        {
            WithoutDI withoutDi = new WithoutDI();

            withoutDi.UseRepo();

            Console.WriteLine();
            Console.WriteLine("Next is our second class wich can work with different repositories.");
            Console.WriteLine();

            WithDI withDbDi = new WithDI(new DbRepository());
            WithDI withFileDi = new WithDI(new FileRepository());

            withDbDi.UseRepo();
            withFileDi.UseRepo();

            Console.WriteLine();
            Console.WriteLine("IOC demo");

            IOC ioc = new IOC();

            ioc.Register("someRepo", new DbRepository());
            ioc.Register("OtherRepo", new FileRepository());

            Console.ReadLine();
        }
Exemplo n.º 2
0
 public WithIOC(IOC ioc)
 {
     _repository = (IRepository)ioc.Resolve("someRepo");
 }