public void TestDisposeAndReConfiguration() { var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig()); Assert.IsNotNull(container); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); container.ExpandConfiguration(new ComplexConfig()); Assert.IsTrue(container.ContainsObject<IAggregate>()); container.Reconfigure(); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); Assert.IsTrue(container.ContainsObject<IAggregate>()); IAggregate aggregate = container.GetObject<IAggregate>(); Assert.IsNotNull(aggregate); var b = container.GetObject("SomeDomainCmdServiceB"); Assert.IsNotNull(b); container.Dispose(); Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject("SomeDomainCmdServiceB")); container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig()); Assert.IsNotNull(container); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); container.ExpandConfiguration(new ComplexConfig()); Assert.IsTrue(container.ContainsObject<IAggregate>()); container.Reconfigure(); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); Assert.IsTrue(container.ContainsObject<IAggregate>()); aggregate = container.GetObject<IAggregate>(); Assert.IsNotNull(aggregate); b = container.GetObject("SomeDomainCmdServiceB"); Assert.IsNotNull(b); }
public void TestGetObjectsInheritingFromPrototypeSuperClassFromContainer() { var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig()); container.ExpandConfiguration(new ComplexConfig()); container.Reconfigure(); List<Prototype> prototypes = container.GetAllObjectsInheriting<Prototype>(); Assert.AreEqual(1, prototypes.Count); }
public void TestGetObjectsInheritingFromSuperClassFromContainer() { var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig()); container.ExpandConfiguration(new ComplexConfig()); container.Reconfigure(); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); Assert.IsTrue(container.ContainsObject<IAggregate>()); List<ISomeDomainCmdService> someDomainCmdServices = container.GetAllObjectsInheriting<ISomeDomainCmdService>(); Assert.AreEqual(2, someDomainCmdServices.Count); List<SomeDomainCmdServiceC> someDomainCmdServicesC = container.GetAllObjectsInheriting<SomeDomainCmdServiceC>(); Assert.AreEqual(0, someDomainCmdServicesC.Count); }
public void TestGetObjectFromContainer() { var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig()); container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()); container.Reconfigure(); Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>()); Assert.IsTrue(container.ContainsObject<ICommandManager>()); Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB")); Assert.IsTrue(container.ContainsObject<IAggregate>()); IAggregate aggregate = container.GetObject<IAggregate>(); Assert.IsNotNull(aggregate); var b = container.GetObject("SomeDomainCmdServiceB"); Assert.IsNotNull(b); // If some instance uniquely implements interface but the object definition id is specified, can it still be retrieved through the interface?? ISomeNewDomainCmdService newCmdService = container.GetObject<ISomeNewDomainCmdService>(); Assert.IsNotNull(newCmdService); SomeNewDomainCmdService newCmdService2 = container.GetObject<SomeNewDomainCmdService>(); Assert.IsNotNull(newCmdService2); var serviceD = container.GetObject<SomeDomainCmdServiceD>("D"); Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<ISomeDomainCmdService>()); Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>()); Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>("E")); Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<INotImplementedInterface>()); }