public void SetUp() { services = new GetDISeriveCollection(); //Registers the services.AddSingleton<T>(TService T) services.AddSingleton <RandomGuidGenerator>(new RandomGuidGenerator()); //build conainer from services container = services.BuildContainer(); }
static void Main(string[] args) { var services = new GetDISeriveCollection(); //Registers the services services.AddSingleton <RandomGuidGenerator>(); //services.AddSingleton<RandomGuidGenerator>(new RandomGuidGenerator()); //services.AddTransient<RandomGuidGenerator>(new RandomGuidGenerator()); //services.AddTransient<RandomGuidGenerator>(); //build conainer from services var container = services.BuildContainer(); //Resolve the service var service1 = container.GetService <RandomGuidGenerator>(); var service2 = container.GetService <RandomGuidGenerator>(); //singleton gets unique guid for all service instance Console.WriteLine(service1.UniqueGuid); Console.WriteLine(service2.UniqueGuid); Console.ReadKey(); }