static void Step1() { Console.WriteLine("---- Step1 ----"); ContainerBuilder containerBuilder = new ContainerBuilder(); containerBuilder.RegisterType <MonService>().As <IService>().As <IAutreService>(); Container = containerBuilder.Build(); using (ILifetimeScope scope = Container.BeginLifetimeScope()) { IService service = scope.Resolve <IService>(); service.AfficherMessage("Hello World"); IAutreService otherservice = scope.Resolve <IAutreService>(); otherservice.AfficherMessage(); } }
static void Step2() { Console.WriteLine("---- Step2 ----"); ContainerBuilder containerBuilder = new ContainerBuilder(); containerBuilder.Register(c => { return(new MonService() { Message = "Hello Parameter" }); }).As <IService>().As <IAutreService>(); Container = containerBuilder.Build(); using (ILifetimeScope scope = Container.BeginLifetimeScope()) { IService service = scope.Resolve <IService>(); service.AfficherMessage("Hello World"); IAutreService otherservice = scope.Resolve <IAutreService>(); otherservice.AfficherMessage(); } }