コード例 #1
0
        public void GetAllInstances_MultipleOpenGenericTypesAppendedToPreRegistrationWithOpenGenericType_ResolvesTheExpectedCollection()
        {
            // Arrange
            Type[] expectedHandlerTypes = new[]
            {
                typeof(NewConstraintEventHandler<StructEvent>),
                typeof(StructConstraintEventHandler<StructEvent>),
                typeof(AuditableEventEventHandler<StructEvent>)
            };

            var container = ContainerFactory.New();

            container.RegisterCollection(typeof(IEventHandler<>), new[] { typeof(NewConstraintEventHandler<>) });

            container.AppendToCollection(typeof(IEventHandler<>), typeof(StructConstraintEventHandler<>));
            container.AppendToCollection(typeof(IEventHandler<>), typeof(AuditableEventEventHandler<>));

            // Act
            Type[] actualHandlerTypes = container.GetAllInstances(typeof(IEventHandler<StructEvent>))
                .Select(h => h.GetType()).ToArray();

            // Assert
            Assert.AreEqual(
                expected: expectedHandlerTypes.ToFriendlyNamesText(),
                actual: actualHandlerTypes.ToFriendlyNamesText());
        }
コード例 #2
0
        public void GetAllInstances_RegistrationPrependedToExistingOpenGenericRegistration_ResolvesTheExtectedCollection()
        {
            // Arrange
            Type[] expectedHandlerTypes = new[]
            {
                typeof(StructEventHandler),
                typeof(NewConstraintEventHandler<StructEvent>),
            };

            var container = ContainerFactory.New();

            var registration = Lifestyle.Transient.CreateRegistration<StructEventHandler>(container);

            container.AppendToCollection(typeof(IEventHandler<>), registration);

            container.RegisterCollection(typeof(IEventHandler<>), new[] { typeof(NewConstraintEventHandler<>) });

            // Act
            Type[] actualHandlerTypes = container.GetAllInstances(typeof(IEventHandler<StructEvent>))
                .Select(h => h.GetType()).ToArray();

            // Assert
            Assert.AreEqual(
                expected: expectedHandlerTypes.ToFriendlyNamesText(),
                actual: actualHandlerTypes.ToFriendlyNamesText());
        }