Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using TinyIoC;
  3.  
  4. namespace TinyIoCTest
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main (string[] args)
  9.         {
  10.             var container = TinyIoCContainer.Current;
  11.             container.Register<IEngine, CheapEngine>().AsMultiInstance();
  12.             //container.Register<IEngine, CheapEngine>().AsSingleton();
  13.             IEngine engine = container.Resolve<IEngine>();
  14.             engine.Start();
  15.             engine.Stop();
  16.             Console.WriteLine ("Hello World!");
  17.             Car c = new Car(container.Resolve<IEngine>());
  18.             c.Start();
  19.         }
  20.     }
  21.    
  22.     public class Car{
  23.         public Car (IEngine e)
  24.         {
  25.             this._Engine = e;
  26.            
  27.         }
  28.         public IEngine _Engine {get;set;}
  29.        
  30.         public void Start() {
  31.             _Engine.Start();
  32.         }
  33.     }
  34.    
  35.     public interface IEngine
  36.     {
  37.         void Start();
  38.         void Stop();
  39.     }
  40.    
  41.     class PowerfullEngine:IEngine
  42.     {
  43.         public void Start ()
  44.         {
  45.             Console.WriteLine("Vruuuuuummmm vruuuuum");
  46.         }
  47.         public void Stop ()
  48.         {
  49.             Console.WriteLine("pooo po po po...");
  50.         }
  51.     }
  52.    
  53.     class CheapEngine:IEngine
  54.     {
  55.         public int istance {get;set;}
  56.         public void Start ()
  57.         {
  58.             istance += 1;
  59.             Console.WriteLine("Prorirrioooodpdpdpdp" + istance.ToString());
  60.         }
  61.         public void Stop ()
  62.         {
  63.             Console.WriteLine("skatafrunkkk traaaak!7#@!!!@#@");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement