public void LaterRegistrationsOverrideEarlierRegistrations()
        {
            var cb = new ContainerBuilder();

            var instance1 = new ConcreteSampleService("one");
            var instance2 = new ConcreteSampleService("two");
            var instance3 = new ConcreteSampleService("three");

            // register my service
            cb.RegisterInstance(instance1)
            .As <ISampleService>();
            // later registration will override previous
            cb.RegisterInstance(instance2)
            .As <ISampleService>();

            cb.RegisterInstance(instance3)
            .As <ISampleService>()
            // unless we use "PreserveExistingDefaults"
            .PreserveExistingDefaults();
            var container = cb.Build();


            // The last registered instance will be resolved here
            var service = container.Resolve <ISampleService>();

            Assert.IsNotNull(service, "service");
            Assert.AreEqual("two", service.Do(), @" ""two"" vs service.Do()");
        }
        public void CanRegisterDecorator()
        {
            var cb = new ContainerBuilder();

            var instance1 = new ConcreteSampleService("one");



            // register my service
            cb.RegisterInstance(instance1)
            .As <ISampleService>();


            // register a decorator for the service
            cb.RegisterDecorator <DecoratorService, ISampleService>();


            var container = cb.Build();

            var service = container.Resolve <ISampleService>() as DecoratorService;

            Assert.IsNotNull(service, "service");

            Assert.IsTrue(service.Do().Contains("<wrapped>"), @" service.Do().Contains(""<wrapped>"") ");
            Assert.IsTrue(service.Do().Contains("one"), @" service.Do().Contains(""one"") ");

            Assert.IsInstanceOf <ConcreteSampleService>(service.Inner);
        }
        public void CanGetAListOfAllRegisteredServices()
        {
            var cb = new ContainerBuilder();

            var instance1 = new ConcreteSampleService("one");
            var instance2 = new ConcreteSampleService("two");
            var instance3 = new ConcreteSampleService("named");

            // register multiple instances

            // named service won't be included unless it is also registered without the name
            cb.RegisterInstance(instance3)
            .As <ISampleService>()
            .Named <ISampleService>("name");

            cb.RegisterInstance(instance1)
            .As <ISampleService>();

            cb.RegisterInstance(instance2)
            .As <ISampleService>();



            var container = cb.Build();


            // The last registered instance will be resolved here
            var service = container.Resolve <ISampleService>();

            Assert.IsNotNull(service, "service");
            Assert.AreEqual("two", service.Do(), @" ""two"" vs service.Do()");

            // I can resolve IEnumerable<Type> even though I didn't explicitly register it
            var services = container.Resolve <IEnumerable <ISampleService> >();

            Assert.IsNotNull(services, "services");
            Assert.AreEqual(services.Count(), 3, @" services.Count() vs 2");

            // IList<Type> also works
            var serviceList = container.Resolve <IList <ISampleService> >();

            Assert.IsNotNull(serviceList, "serviceList");
        }