示例#1
0
        /// <summary>
        /// Registers an <paramref name="implementationType"/> for generation with the <see cref="Registrations"/>.
        /// </summary>
        /// <param name="serviceType">
        /// The type of the service to by satisfied during registration. The <paramref name="serviceType"/> should be
        /// satisfied by being <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> the
        /// <paramref name="implementationType"/>.
        /// </param>
        /// <param name="implementationType">The type of the implemented service to provide.</param>
        /// <param name="compose">The action to further compose the registration.</param>
        /// <returns><see langword="this"/> context to be used in a fluent configuration.</returns>
        public TDerived Register(
            Type serviceType,
            Type implementationType,
            Action <RegistrationComposer> compose = null)
        {
            if (implementationType == null)
            {
                throw new ArgumentNullException(nameof(implementationType));
            }
            if (serviceType == null)
            {
                throw new ArgumentNullException(nameof(serviceType));
            }

            IRegistration defaultRegistration = new SingleConstructorRegistration(implementationType);

            if (compose == null)
            {
                return(Register(serviceType, defaultRegistration));
            }

            var composer = new RegistrationComposer(defaultRegistration);

            compose(composer);

            return(Register(serviceType, composer.Registration));
        }
示例#2
0
        /// <summary>
        /// Registers an <typeparamref name="TImplementation"/> for generation with the <see cref="Registrations"/>.
        /// </summary>
        /// <typeparam name="TService">
        /// The type of the service to by satisfied during registration. The <typeparamref name="TService"/> should be
        /// satisfied by being <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> the
        /// <typeparamref name="TImplementation"/>.
        /// </typeparam>
        /// <typeparam name="TImplementation">The type of the implemented service.</typeparam>
        /// <param name="compose">The action to further compose the registration.</param>
        /// <returns><see langword="this"/> context to be used in a fluent configuration.</returns>
        public TDerived Register <TService, TImplementation>(
            Action <RegistrationComposer <TImplementation> > compose = null)
            where TImplementation : TService
        {
            IRegistration defaultRegistration = new SingleConstructorRegistration(typeof(TImplementation));

            if (compose == null)
            {
                return(Register(typeof(TService), defaultRegistration));
            }

            var composer = new RegistrationComposer <TImplementation>(defaultRegistration);

            compose(composer);

            return(Register(typeof(TService), composer.Registration));
        }