/// <summary>
        /// Add a registration source to the container.
        /// </summary>
        /// <param name="builder">The builder to register the registration source with.</param>
        /// <typeparam name="TRegistrationSource">The registration source to add.</typeparam>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="builder"/> is <see langword="null"/>.
        /// </exception>
        /// <returns>
        /// The <see cref="ISourceRegistrar"/> to allow additional chained registration source registrations.
        /// </returns>
        public static ISourceRegistrar RegisterSource <TRegistrationSource>(this ContainerBuilder builder)
            where TRegistrationSource : IRegistrationSource, new()
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var registrar = new SourceRegistrar(builder);

            return(registrar.RegisterSource <TRegistrationSource>());
        }
        public void RegisterSource_ChainsSourceRegistrations()
        {
            var builder   = new ContainerBuilder();
            var registrar = new SourceRegistrar(builder);

            registrar.RegisterSource <SourceA>()
            .RegisterSource(new ObjectRegistrationSource(O2));

            var container = builder.Build();
            var objects   = container.Resolve <IEnumerable <object> >();

            Assert.Contains(O1, objects);
            Assert.Contains(O2, objects);
        }
Beispiel #3
0
        /// <summary>
        /// Add a registration source to the container.
        /// </summary>
        /// <param name="builder">The builder to register the registration source via.</param>
        /// <param name="registrationSource">The registration source to add.</param>
        /// <returns>
        /// The <see cref="ISourceRegistrar"/> to allow additional chained registration source registrations.
        /// </returns>
        public static ISourceRegistrar RegisterSource(this ContainerBuilder builder, IRegistrationSource registrationSource)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (registrationSource == null)
            {
                throw new ArgumentNullException(nameof(registrationSource));
            }

            var registrar = new SourceRegistrar(builder);

            return(registrar.RegisterSource(registrationSource));
        }
        public void RegisterSource_RequiresRegistrationSource()
        {
            var registrar = new SourceRegistrar(new ContainerBuilder());

            Assert.Throws <ArgumentNullException>(() => registrar.RegisterSource(null));
        }