Пример #1
0
        public void Get_When_Instance_Is_Registered()
        {
            // Arrange
            var container = ContainerFactory.Create();

            var instance = new ContainerTestClass();

            container.RegisterInstance <IContainerTestInterface, ContainerTestClass>(instance);

            // Act
            var returnedInstance = container.Get <IContainerTestInterface>();

            // Assert
            Assert.IsNotNull(returnedInstance);
            Assert.AreSame(instance, returnedInstance);
        }
Пример #2
0
        public void Get_When_FactoryMethod_Is_Registered_And_Property_Is_Injected()
        {
            // Arrange
            var container = ContainerFactory.Create();

            var instance1 = new ContainerTestClass();

            container.RegisterInstance <IContainerTestInterface>(instance1);

            container.RegisterFactoryMethod <IContainerTestInterfaceWithInjectedProperties>(c => new ContainerTestInterfaceWithInjectedProperties());

            // Act
            var instance2 = container.Get <IContainerTestInterfaceWithInjectedProperties>();

            // Assert
            Assert.IsNotNull(instance2);
            Assert.AreSame(instance1, instance2.Instance);
        }