Beispiel #1
0
        /// <summary>
        /// Adds a transient service to instantiate a new <see cref="EventHubConsumerHost"/> instance using the specified <paramref name="args"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="args">The <see cref="EventSubscriberHostArgs"/>.</param>
        /// <param name="addSubscriberTypeServices">Indicates whether to add all the <see cref="EventSubscriberHostArgs.GetSubscriberTypes"/> as scoped services (defaults to <c>true</c>).</param>
        /// <param name="additional">Optional (additional) opportunity to further configure the instantiated <see cref="EventHubConsumerHost"/>.</param>
        /// <returns>The <see cref="IServiceCollection"/> for fluent-style method-chaining.</returns>
        public static IServiceCollection AddBeefEventHubConsumerHost(this IServiceCollection services, EventSubscriberHostArgs args, bool addSubscriberTypeServices = true, Action <IServiceProvider, EventHubConsumerHost>?additional = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            services.AddTransient(sp =>
            {
                var ehsh = new EventHubConsumerHost(args);
                args.UseServiceProvider(sp);
                additional?.Invoke(sp, ehsh);
                return(ehsh);
            });

            if (addSubscriberTypeServices)
            {
                foreach (var type in args.GetSubscriberTypes())
                {
                    services.TryAddScoped(type);
                }
            }

            return(services);
        }
Beispiel #2
0
        public void Ctor_SubscribersInAssembly()
        {
            var ts = EventSubscriberHostArgs.GetSubscriberTypes(this.GetType().Assembly);

            Assert.AreEqual(2, ts.Length);
        }