public void ShouldGetDifferentInstanceOfTransientRegisteredType()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddTransient <IMessageHandler <MyMessage>, MyMessageHandler>();

            var busContainer = new ServiceCollectionContainer();

            busContainer.Initialize(services);

            // Act
            var result1 = busContainer.GetInstance(typeof(IMessageHandler <MyMessage>));
            var result2 = busContainer.GetInstance(typeof(IMessageHandler <MyMessage>));

            // Assert
            Assert.NotNull(result1);
            Assert.NotNull(result2);
            Assert.Equal("MyMessageHandler", result1.GetType().Name);
            Assert.Equal("MyMessageHandler", result2.GetType().Name);
            Assert.NotSame(result1, result2);
        }
示例#2
0
        public void ShouldGetInstanceOfRegisteredType()
        {
            // Arrange
            var busContainer = new ServiceCollectionContainer();

            busContainer.AddHandler(typeof(IMessageHandler <MyMessage>), new MyMessageHandler());


            // Act
            var result = busContainer.GetInstance(typeof(IMessageHandler <MyMessage>));

            // Assert
            Assert.NotNull(result);
            Assert.Equal("MyMessageHandler", result.GetType().Name);
        }
示例#3
0
        public void ShouldGetInstanceOfRegisteredTypeWithCtorParameters()
        {
            // Arrange
            var busContainer = new ServiceCollectionContainer();

            busContainer.AddHandler(typeof(IMessageHandler <MyMessage>), new MyMessageHandler2("TestName"));

            // Act
            var result = busContainer.GetInstance <IMessageHandler <MyMessage> >(new Dictionary <string, object> {
                { "name", "TestName" }
            });

            // Assert
            Assert.NotNull(result);
            Assert.Equal("MyMessageHandler2", result.GetType().Name);
        }