public void WhenInstanceRegisteredAsSingletonThenGetSameInstance()
        {
            var factory    = new SimpleServiceContainer();
            var myInstance = new MyService();

            factory.RegisterSingleton <IMyService>(myInstance);

            var actual = factory.GetInstance <IMyService>();

            actual.Should().Be.SameInstanceAs(myInstance);
        }
Exemplo n.º 2
0
        static SharedDicTestContext()
        {
            _allPlugins   = new List <INamedVersionedUniqueId>();
            _allPluginsEx = new ReadOnlyListOnIList <INamedVersionedUniqueId>(_allPlugins);
            EnsurePlugins(10);

            var c = new SimpleServiceContainer();

            c.Add <ISimpleTypeFinder>(SimpleTypeFinder.Default);
            _serviceProvider = c;
        }
Exemplo n.º 3
0
        public static void RegisterAllServices(this SimpleServiceContainer store)
        {
            var repoFactory = new GenericRepositoryFactory(store, store);

            store.RegisterSingleton <IRepositoryFactory>(c => repoFactory);
            var reports = new ReportsProvider();

            store.RegisterSingleton <IReportsProvider>(reports);
            store.RegisterSingleton <IReportsStore>(reports);
            RegisterRepositories(repoFactory);
        }
        public void WhenTransientServiceThenGetNewInstance()
        {
            var factory = new SimpleServiceContainer();

            factory.RegisterTransient <IMyService>(x => new MyService());

            var first  = factory.GetInstance <IMyService>();
            var actual = factory.GetInstance <IMyService>();

            actual.Should().Not.Be.SameInstanceAs(first);
        }
Exemplo n.º 5
0
        public void registering_a_simple_class()
        {
            ISimpleServiceContainer container     = new SimpleServiceContainer();
            ProvidedClass           providedClass = new ProvidedClass(5);

            container.Add(providedClass);

            ProvidedClass retrievedObject = container.GetService <ProvidedClass>();

            retrievedObject.Should().NotBeNull();
            retrievedObject.Age.Should().Be(5);
        }
Exemplo n.º 6
0
        public void registering_a_simple_class()
        {
            ISimpleServiceContainer container     = new SimpleServiceContainer();
            ProvidedClass           providedClass = new ProvidedClass(5);

            container.Add(providedClass);

            ProvidedClass retrievedObject = container.GetService <ProvidedClass>();

            Assert.That(retrievedObject, Is.Not.Null);
            Assert.That(retrievedObject.Age, Is.EqualTo(5));
        }
Exemplo n.º 7
0
 GitFolder(Repository r, ProtoGitFolder data)
     : base(data, r, data.FullPhysicalPath, data.FolderPath)
 {
     _headFolder           = new HeadFolder(this);
     _branchesFolder       = new BranchesFolder(this, "branches", isRemote: false);
     _remoteBranchesFolder = new RemotesFolder(this);
     _thisDir         = new RootDir(this, SubPath.LastPart);
     ServiceContainer = new SimpleServiceContainer(FileSystem.ServiceContainer);
     ServiceContainer.Add(this);
     PluginManager = new GitPluginManager(data.PluginRegistry, ServiceContainer, data.CommandRegister, data.World.DevelopBranchName);
     data.CommandRegister.Register(this);
 }
 public GenBinPath(StObjEngineRunContext global,
                   StObjCollectorResult result,
                   RunningBinPathGroup group)
 {
     Debug.Assert(!result.HasFatalError);
     _global            = global;
     Result             = result;
     ConfigurationGroup = group;
     Memory             = new Dictionary <object, object?>();
     ServiceContainer   = new SimpleServiceContainer(_global.ServiceContainer);
     ServiceContainer.Add(result.DynamicAssembly.GetPocoSupportResult());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new plugin manager.
 /// </summary>
 /// <param name="registry">The registry of plugins.</param>
 /// <param name="baseProvider">The base service provider.</param>
 /// <param name="commandRegister">Command registerer.</param>
 /// <param name="defaultBranchName">The default branch name (typically "develop"). Must not be null or empty.</param>
 public GitPluginManager(GitPluginRegistry registry, ISimpleServiceContainer baseProvider, CommandRegister commandRegister, string defaultBranchName)
 {
     if (String.IsNullOrWhiteSpace(defaultBranchName))
     {
         throw new ArgumentNullException(nameof(defaultBranchName));
     }
     ServiceContainer   = new SimpleServiceContainer(baseProvider);
     _defaultBranchName = defaultBranchName;
     _commandRegister   = commandRegister ?? throw new ArgumentNullException(nameof(commandRegister));
     Registry           = registry;
     _plugins           = new PluginCollection <IGitPlugin>(this, null);
     _branches          = new Branches(this);
 }
            public void DoTest()
            {
                var extraServices = new SimpleServiceContainer();

                extraServices.Add <Func <string> >(() => "Hello World!");

                StObjCollector collector = new StObjCollector(TestHelper.Monitor, extraServices);

                collector.RegisterType(typeof(JustForTheAttribute));
                var r = collector.GetResult();

                Assert.That(r.HasFatalError, Is.False);
            }
Exemplo n.º 11
0
 public WriterImpl(XmlWriter writer, IServiceProvider baseServiceProvider, bool writeElementHeader, bool autoCloseWriter)
     : base(null)
 {
     _xmlWriter        = writer;
     _serviceContainer = new SimpleServiceContainer(baseServiceProvider);
     if (writeElementHeader)
     {
         Xml.WriteStartElement("CK-Structured");
         Xml.WriteAttributeString("version", "2.5.5");
         _mustEndElement = true;
     }
     _mustCloseWriter = autoCloseWriter;
     Current          = this;
 }
Exemplo n.º 12
0
 internal StObjEngineConfigureContext(IActivityMonitor monitor,
                                      RunningStObjEngineConfiguration config,
                                      IStObjEngineStatus status,
                                      bool canSkipRun)
 {
     _monitor                = monitor;
     _config                 = config;
     _status                 = status;
     _aspects                = new List <IStObjEngineAspect>();
     _configurator           = new StObjEngineConfigurator();
     _container              = new Container(this);
     _configureOnlycontainer = new SimpleServiceContainer(_container);
     _trampoline             = new StObjEngineAspectTrampoline <IStObjEngineConfigureContext>(this);
     _canSkipRun             = canSkipRun;
 }
Exemplo n.º 13
0
        public void SimpleServiceContainerGetDirectServiceTest()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();

            Assert.That(container.GetService <IServiceProvider>() == container);
            Assert.That(container.GetService <ISimpleServiceContainer>() == container);

            Assert.Throws <CKException>(() => container.Add <ISimpleServiceContainer>(container));
            Assert.Throws <CKException>(() => container.Add <ISimpleServiceContainer>(new SimpleServiceContainer()));
            Assert.Throws <CKException>(() => container.AddDisabled(typeof(ISimpleServiceContainer)));

            Assert.Throws <CKException>(() => container.Add <IServiceProvider>(container));
            Assert.Throws <CKException>(() => container.Add <IServiceProvider>(new SimpleServiceContainer()));
            Assert.Throws <CKException>(() => container.AddDisabled(typeof(IServiceProvider)));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new <see cref="FileSystem"/> on a physical root path.
 /// </summary>
 /// <param name="rootPath">Physical root path.</param>
 /// <param name="commandRegister">Command register.</param>
 /// <param name="sp">Optional base services.</param>
 public FileSystem(
     string rootPath,
     CommandRegister commandRegister,
     SecretKeyStore secretKeyStore,
     IServiceProvider sp)
 {
     Root             = new NormalizedPath(Path.GetFullPath(rootPath));
     _commandRegister = commandRegister;
     _secretKeyStore  = secretKeyStore;
     _protoGits       = new List <ProtoGitFolder>();
     _gits            = new List <GitFolder>();
     ServiceContainer = new SimpleServiceContainer(sp);
     ServiceContainer.Add(this);
     ServiceContainer.Add <IFileProvider>(this);
 }
Exemplo n.º 15
0
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            var container = new SimpleServiceContainer();

            container.RegisterAllServices();
            config.UseSimpleDependencyResolver(container);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api1/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Exemplo n.º 16
0
        public void SimpleServiceContainerTest()
        {
            int removedServicesCount = 0;

            IServiceContainerConformanceTest(new SimpleServiceContainer());

            ISimpleServiceContainer baseProvider = new SimpleServiceContainer();
            IMultService            multService  = new MultServiceImpl();

            baseProvider.Add(typeof(IMultService), multService, o => removedServicesCount++);
            ISimpleServiceContainer container = new SimpleServiceContainer(baseProvider);

            IServiceContainerConformanceTest(container, baseProvider, baseProvider.GetService <IMultService>());

            Assert.That(removedServicesCount, Is.EqualTo(1));
        }
Exemplo n.º 17
0
        public void SimpleServiceContainer_exposes_its_own_IServiceProvier_and_ISimpleServiceContainer_implementation()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();

            container.GetService <IServiceProvider>().Should().BeSameAs(container);
            container.GetService <ISimpleServiceContainer>().Should().BeSameAs(container);

            container.Invoking(sut => sut.Add <ISimpleServiceContainer>(container)).Should().Throw <Exception>();
            container.Invoking(sut => sut.Add <ISimpleServiceContainer>(new SimpleServiceContainer())).Should().Throw <Exception>();
            container.Invoking(sut => sut.Add <ISimpleServiceContainer>(JustAFunc <ISimpleServiceContainer>)).Should().Throw <Exception>();

            container.Invoking(sut => sut.Add <IServiceProvider>(container)).Should().Throw <Exception>();
            container.Invoking(sut => sut.Add <IServiceProvider>(new SimpleServiceContainer())).Should().Throw <Exception>();
            container.Invoking(sut => sut.Add <IServiceProvider>(JustAFunc <IServiceProvider>)).Should().Throw <Exception>();
            container.Invoking(sut => sut.AddDisabled(typeof(IServiceProvider))).Should().Throw <Exception>();
        }
Exemplo n.º 18
0
        public void SimpleServiceContainer_exposes_its_own_IServiceProvier_and_ISimpleServiceContainer_implementation()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();

            Assert.That(container.GetService <IServiceProvider>() == container);
            Assert.That(container.GetService <ISimpleServiceContainer>() == container);

            Assert.Throws <CKException>(() => container.Add <ISimpleServiceContainer>(container));
            Assert.Throws <CKException>(() => container.Add <ISimpleServiceContainer>(new SimpleServiceContainer()));
            Assert.Throws <CKException>(() => container.Add <ISimpleServiceContainer>(JustAFunc <ISimpleServiceContainer>));

            Assert.Throws <CKException>(() => container.Add <IServiceProvider>(container));
            Assert.Throws <CKException>(() => container.Add <IServiceProvider>(new SimpleServiceContainer()));
            Assert.Throws <CKException>(() => container.Add <IServiceProvider>(JustAFunc <IServiceProvider>));
            Assert.Throws <CKException>(() => container.AddDisabled(typeof(IServiceProvider)));
        }
Exemplo n.º 19
0
        public void checking_null_arguments()
        {
            ISimpleServiceContainer container = new SimpleServiceContainer();

            //SimpleServiceContainer.Add( Type serviceType, object serviceInstance, Action<Object> onRemove = null )
            Assert.Throws <ArgumentNullException>(() => container.Add(null, new ProvidedClass(5)));
            Assert.Throws <ArgumentNullException>(() => container.Add(typeof(ProvidedClass), (object)null));

            //SimpleServiceContainer.Add( Type serviceType, Func<Object> serviceInstance, Action<Object> onRemove = null )
            Assert.Throws <ArgumentNullException>(() => container.Add(null, JustAFunc));
            Assert.Throws <ArgumentNullException>(() => container.Add(typeof(ProvidedClass), (Func <Object>)null));

            Assert.Throws <ArgumentNullException>(() => container.AddDisabled(null));
            Assert.Throws <ArgumentNullException>(() => container.GetService(null));
            Assert.Throws <ArgumentNullException>(() => container.Add <ProvidedClass>(JustAFunc <ProvidedClass>, null));
        }
Exemplo n.º 20
0
        public void registering_an_implementation()
        {
            int removedServicesCount = 0;

            IServiceContainerConformanceTest(new SimpleServiceContainer());

            ISimpleServiceContainer baseProvider = new SimpleServiceContainer();
            IMultService            multService  = new MultServiceImpl();

            multService.Mult(3, 7).Should().Be(21);
            baseProvider.Add(typeof(IMultService), multService, o => removedServicesCount++);
            ISimpleServiceContainer container = new SimpleServiceContainer(baseProvider);

            IServiceContainerConformanceTest(container, baseProvider, baseProvider.GetService <IMultService>());

            removedServicesCount.Should().Be(1);
        }
Exemplo n.º 21
0
        private bool HandleStObjPropertySource(IActivityMonitor monitor, StObjProperty p, MutableItem source, string sourceName, bool doSetOrMerge)
        {
            StObjProperty?c = source.GetStObjProperty(p.Name);

            // Source property is defined somewhere in the source.
            if (c != null)
            {
                // If the property is explicitly defined (Info != null) and its type is not
                // compatible with our, there is a problem.
                if (c.InfoOnType != null && !p.Type.IsAssignableFrom(c.Type))
                {
                    // It is a warning because if actual values work, everything is okay... but one day, it should fail.
                    var msg = String.Format("StObjProperty '{0}.{1}' of type '{2}' is not compatible with the one of its {6} ('{3}.{4}' of type '{5}'). Type should be compatible since {6}'s property value will be propagated if no explicit value is set for '{7}.{1}' or if '{3}.{4}' is set with an incompatible value.",
                                            ToString(), p.Name, p.Type.Name,
                                            source.RealObjectType.Type.Name, c.Name, c.Type.Name,
                                            sourceName,
                                            RealObjectType.Type.Name);
                    monitor.Warn(msg);
                }
                if (doSetOrMerge)
                {
                    // The source value must have been set and not explicitly "removed" with a System.Type.Missing value.
                    if (c.Value != System.Type.Missing)
                    {
                        // We "Set" the value from this source.
                        if (!p.ValueHasBeenSet)
                        {
                            p.Value = c.Value;
                        }
                        else if (p.Value is IMergeable)
                        {
                            using (var services = new SimpleServiceContainer())
                            {
                                services.Add(monitor);
                                if (!((IMergeable)p.Value).Merge(c.Value, services))
                                {
                                    monitor.Error($"Unable to merge StObjProperty '{ToString()}.{p.Value}' with value from {sourceName}.");
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
        public void delegated_attribute_handles_constructor_injection_instead_of_initialization()
        {
            OneCtorAttributeImpl.Constructed = false;
            var aspectProvidedServices = new SimpleServiceContainer();

            // Registers this AttributeTests.
            aspectProvidedServices.Add(this);
            var c = new StObjCollector(TestHelper.Monitor, aspectProvidedServices);

            c.RegisterType(typeof(S4));

            var r = TestHelper.GetSuccessfulResult(c);

            Debug.Assert(r.EngineMap != null);
            r.EngineMap.AllTypesAttributesCache.Values.Should().Contain(a => a.Type == typeof(S4));
            OneCtorAttributeImpl.Constructed.Should().BeTrue();
        }
Exemplo n.º 23
0
        public void WriteReadUserConfig()
        {
            string path = Path.Combine(TestFolder, "UserConfig.xml");
            Guid   id   = new Guid("{6AFBAE01-5CD1-4EDE-BB56-4590C5A253DF}");

            // Write ----------------------------------------------------------
            {
                ISharedDictionary      dic    = SharedDictionary.Create(null);
                IConfigManagerExtended config = ConfigurationManager.Create(dic);
                Assert.That(config, Is.Not.Null);
                Assert.That(config.HostUserConfig, Is.Not.Null);
                Assert.That(config.ConfigManager.UserConfiguration, Is.Not.Null);

                config.HostUserConfig["key1"] = "value1";
                config.HostUserConfig["key2"] = "value2";
                config.HostUserConfig["key3"] = "value3";
                config.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.AutomaticStart);

                Assert.That(config.IsUserConfigDirty);
                Assert.That(config.IsSystemConfigDirty, Is.False);

                using (Stream wrt = new FileStream(path, FileMode.Create))
                    using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, null))
                    {
                        config.SaveUserConfig(sw);
                    }
            }

            // Read ------------------------------------------------------------
            {
                ISimpleServiceContainer container = new SimpleServiceContainer();
                ISharedDictionary       dic       = SharedDictionary.Create(container);
                IConfigManagerExtended  config    = ConfigurationManager.Create(dic);

                using (Stream str = new FileStream(path, FileMode.Open))
                    using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, container))
                    {
                        config.LoadUserConfig(sr);
                    }
                Assert.That(config.HostUserConfig["key1"], Is.EqualTo("value1"));
                Assert.That(config.HostUserConfig["key2"], Is.EqualTo("value2"));
                Assert.That(config.HostUserConfig["key3"], Is.EqualTo("value3"));
                Assert.That(config.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id, ConfigPluginStatus.Disabled) == ConfigPluginStatus.AutomaticStart);
            }
        }
Exemplo n.º 24
0
        private static void InitServices()
        {
            var serviceContainer = new SimpleServiceContainer();

            GlobalConfig.ServiceLocator = serviceContainer;
            GlobalConfig.ErrorReportSerializer = new FormErrorReportSerializer();

            var errorReportQueue = new ErrorQueue();
            serviceContainer.AddService(typeof(IWebRequestCreate), new WebRequestFactory());
            serviceContainer.AddService(typeof(IErrorReportSerializer), (container, type) => GlobalConfig.ErrorReportSerializer);
            serviceContainer.AddService(typeof(IReportRequestBuilder), (container, type) => new ReportRequestBuilder());
            serviceContainer.AddService(typeof(IErrorReportStorage), (container, type) => new RemoteErrorReportStorage());
            serviceContainer.AddService(typeof(IErrorReportStorage), (container, type) => new LocalErrorReportStorage());
            serviceContainer.AddService(typeof(IErrorQueue), errorReportQueue);

            var errorHandler = new ErrorHandler();
            serviceContainer.AddService(typeof(IErrorHandler), errorHandler);
        }
 public void OneObjectDirectProperty()
 {
     var container = new SimpleServiceContainer();
     {
         StObjCollector collector = new StObjCollector(TestHelper.Monitor, container);
         collector.RegisterType(typeof(SimpleObjectDirect));
         var map = collector.GetResult().EngineMap;
         Debug.Assert(map != null, "No initialization error.");
         map.StObjs.Obtain <SimpleObjectDirect>() !.OneIntValue.Should().Be(3712, "Direct properties can be set by Attribute.");
     }
     {
         StObjCollector collector = new StObjCollector(TestHelper.Monitor, container, configurator: new ConfiguratorOneIntValueSetTo42());
         collector.RegisterType(typeof(SimpleObjectDirect));
         var map = collector.GetResult().EngineMap;
         Debug.Assert(map != null, "No initialization error.");
         map.StObjs.Obtain <SimpleObjectDirect>() !.OneIntValue.Should().Be(42, "Direct properties can be set by any IStObjStructuralConfigurator participant (here the global one).");
     }
 }
Exemplo n.º 26
0
        public void SimpleServiceContainerRemoveFallbackTest()
        {
            SimpleServiceContainer container       = new SimpleServiceContainer();
            DisposableClass        disposableClass = new DisposableClass();

            disposableClass.ServiceContainer = container;
            container.Add <DisposableClass>(disposableClass, Util.ActionDispose);

            DisposableClass service = container.GetService <DisposableClass>();

            Assert.That(service != null);
            Assert.That(service.GetType(), Is.EqualTo(typeof(DisposableClass)));

            container.Clear();

            Assert.That(container.GetService(typeof(DisposableClass)), Is.Null);
            Assert.That(container.GetService <DisposableClass>(), Is.Null);
            Assert.Throws <CKException>(() => container.GetService <DisposableClass>(true));
        }
 public void OneObjectAmbientProperty()
 {
     var container = new SimpleServiceContainer();
     {
         StObjCollector collector = new StObjCollector(TestHelper.Monitor, container);
         collector.RegisterType(typeof(SimpleObjectAmbient));
         var map = collector.GetResult().EngineMap;
         Debug.Assert(map != null, "No initialization error.");
         map.StObjs.OrderedStObjs.Should().NotBeEmpty("We registered SimpleObjectAmbient.");
         map.StObjs.Obtain <SimpleObjectAmbient>() !.OneIntValue.Should().Be(3712, "Same as Direct properties (above) regarding direct setting. The difference between Ambient and non-ambient lies in value propagation.");
     }
     {
         StObjCollector collector = new StObjCollector(TestHelper.Monitor, container, configurator: new ConfiguratorOneIntValueSetTo42());
         collector.RegisterType(typeof(SimpleObjectAmbient));
         var map = collector.GetResult().EngineMap;
         Debug.Assert(map != null, "No initialization error.");
         map.StObjs.Obtain <SimpleObjectAmbient>() !.OneIntValue.Should().Be(42, "Same as Direct properties (above) regarding direct setting. The difference between Ambient and non-ambient lies in value propagation.");
     }
 }
Exemplo n.º 28
0
        public void clearing_a_container_disposes_all_its_registered_IDisposable_objects_and_remove_reentrancy_is_handled()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();
            DisposableThatReenterClearWhenDisposed disposableClass = new DisposableThatReenterClearWhenDisposed();

            disposableClass.ServiceContainer = container;
            container.Add(disposableClass, Util.ActionDispose);

            DisposableThatReenterClearWhenDisposed service = container.GetService <DisposableThatReenterClearWhenDisposed>();

            service.Should().NotBeNull();
            service.GetType().Should().Be(typeof(DisposableThatReenterClearWhenDisposed));

            container.Clear();

            container.GetService(typeof(DisposableThatReenterClearWhenDisposed)).Should().BeNull();
            container.GetService <DisposableThatReenterClearWhenDisposed>().Should().BeNull();
            container.Invoking(sut => sut.GetService <DisposableThatReenterClearWhenDisposed>(true)).Should().Throw <Exception>();
        }
Exemplo n.º 29
0
        public void clearing_a_container_disposes_all_its_registered_IDisposable_objects_and_remove_reentrancy_is_handled()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();
            DisposableThatReenterClearWhenDisposed disposableClass = new DisposableThatReenterClearWhenDisposed();

            disposableClass.ServiceContainer = container;
            container.Add(disposableClass, Util.ActionDispose);

            DisposableThatReenterClearWhenDisposed service = container.GetService <DisposableThatReenterClearWhenDisposed>();

            Assert.That(service != null);
            Assert.That(service.GetType(), Is.EqualTo(typeof(DisposableThatReenterClearWhenDisposed)));

            container.Clear();

            Assert.That(container.GetService(typeof(DisposableThatReenterClearWhenDisposed)), Is.Null);
            Assert.That(container.GetService <DisposableThatReenterClearWhenDisposed>(), Is.Null);
            Assert.Throws <CKException>(() => container.GetService <DisposableThatReenterClearWhenDisposed>(true));
        }
Exemplo n.º 30
0
        public void using_onRemove_action_reentrancy_of_remove_is_handled()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();
            DisposableThatReenterClearWhenDisposed disposableClass = new DisposableThatReenterClearWhenDisposed();
            EmptyClass stupidObject = new EmptyClass();

            disposableClass.ServiceContainer = container;
            container.Add(disposableClass, Util.ActionDispose);
            container.Add(stupidObject, e => container.Clear());

            DisposableThatReenterClearWhenDisposed service = container.GetService <DisposableThatReenterClearWhenDisposed>();

            Assert.That(service, Is.InstanceOf <DisposableThatReenterClearWhenDisposed>());

            container.Remove <EmptyClass>();

            Assert.That(container.GetService(typeof(DisposableThatReenterClearWhenDisposed)), Is.Null);
            Assert.That(container.GetService <DisposableThatReenterClearWhenDisposed>(), Is.Null);
            Assert.Throws <CKException>(() => container.GetService <DisposableThatReenterClearWhenDisposed>(true));
        }
Exemplo n.º 31
0
        public void removing_a_registered_service()
        {
            int removedServicesCount = 0;

            SimpleServiceContainer container = new SimpleServiceContainer();

            container.Add(typeof(IAddService), new AddServiceImpl(), o => removedServicesCount++);

            IAddService service = container.GetService <IAddService>();

            Assert.That(service, Is.InstanceOf <AddServiceImpl>());

            Assert.That(removedServicesCount, Is.EqualTo(0));
            container.Remove(typeof(IAddService));
            Assert.That(removedServicesCount, Is.EqualTo(1));

            Assert.That(container.GetService(typeof(IAddService)), Is.Null);
            Assert.That(container.GetService <IAddService>(), Is.Null);
            Assert.Throws <CKException>(() => container.GetService <IAddService>(true));
        }
Exemplo n.º 32
0
 public void SetUp()
 {
     container = new SimpleServiceContainer();
 }