Exemple #1
0
        public void ItShouldThrowACompositionException()
        {
            // Arrange
            string expectedMessage =
                $"There is no current composition for the type '{GetType()}'.";

            // Act
            Action action = () => _composition.RemoveComposition(GetType());

            // Assert
            action
            .ShouldThrow <CompositionException>()
            .WithMessage(expectedMessage);
        }
        /// <summary>
        /// Accepts the <see cref="PropertyDependencyRegistration"/> to visit.
        /// </summary>
        /// <param name="registration">The <see cref="PropertyDependencyRegistration"/> to visit.</param>
        public void Accept(PropertyDependencyRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            // Visit the inner registration which will add a composition.
            _manager.Visit(registration.Inner);

            // Get the original composition, removing it to allow it to be replaced.
            IComposition inner = _container.RemoveComposition(registration.ImplementationType);

            (string property, Type type)[] propertiesToInject =
        /// <summary>
        /// Accepts the <see cref="SingletonRegistration"/> to visit.
        /// </summary>
        /// <param name="registration">The <see cref="SingletonRegistration"/> to visit.</param>
        public void Accept(SingletonRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            // Visit the inner registration which will add a composition.
            _manager.Visit(registration.Inner);

            // Get the original composition, removing it to allow it to be replaced.
            IComposition inner = _container.RemoveComposition(registration.ImplementationType);

            // Replace the inner composition.
            IComposition composition = new SingletonComposition(inner);

            _container.AddComposition(composition);
        }