Esempio n. 1
0
        static void Main(string[] args)
        {
            var dobbyContainer = new DobbyContainer();

            dobbyContainer.Register <IMailSender, MailSender>(new SingletonLifetimeManager());
            dobbyContainer.Register <ISmsSender, SmsSender>();

            var smsSender  = dobbyContainer.Resolve <ISmsSender>();
            var mailSender = dobbyContainer.Resolve <IMailSender>();
            var mailSenderSecondResolve = dobbyContainer.Resolve <IMailSender>();

            smsSender.Send();

            mailSender.Send();
            mailSenderSecondResolve.Send();

            var childContainer = dobbyContainer.CreateAndGetChildContainer();

            var thirdMailSender = childContainer.Resolve <IMailSender>();

            thirdMailSender.Send();

            childContainer.Dispose();

            var fourthMailSender = dobbyContainer.Resolve <IMailSender>();

            fourthMailSender.Send();

            Console.Read();
        }
 public void Execute(DobbyContainer dobbyContainer)
 {
     dobbyContainer.Register <IMessageService, MailService>(new PerRequestLifetimeManager());
 }