Beispiel #1
0
        public void RemovePromotedServiceInstance()
        {
            ContainerAdapter child = new ContainerAdapter();

            container.Add(child);

            ICalcService service = new CalculatorService();

            child.AddService(typeof(ICalcService), service, true);
            Assert.IsNotNull(child.GetService(typeof(ICalcService)));

            child.RemoveService(typeof(ICalcService), true);
            Assert.IsNull(child.GetService(typeof(ICalcService)));
            Assert.IsNull(container.GetService(typeof(ICalcService)));
        }
Beispiel #2
0
        public void AddPromotedServiceCreatorCallback()
        {
            ContainerAdapter child = new ContainerAdapter();

            container.Add(child);

            ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateCalculatorService);

            child.AddService(typeof(ICalcService), callback, true);

            ICalcService service = (ICalcService)child.GetService(typeof(ICalcService));

            Assert.IsNotNull(service);

            ICalcService promotedService = (ICalcService)container.GetService(typeof(ICalcService));

            Assert.IsNotNull(service);

            Assert.AreSame(service, promotedService);

            container.Remove(child);
            Assert.IsNull(child.GetService(typeof(ICalcService)));
            Assert.AreSame(container.GetService(typeof(ICalcService)), service);
        }