Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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();
            }
        }