Пример #1
0
        /// <summary>
        /// Adds an <see cref="ISender"/> to the service collection.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="registration">
        /// The registration delegate that is responsible for creating the <see cref="ISender"/>.
        /// </param>
        /// <param name="lifetime">The <see cref="ServiceLifetime"/> of the sender.</param>
        /// <returns>A new <see cref="ISenderBuilder"/> for decorating the <see cref="ISender"/>.</returns>
        public static ISenderBuilder AddSender(this IServiceCollection services, SenderRegistration registration,
                                               ServiceLifetime lifetime = _defaultLifetime)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (registration is null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            var builder = new SenderBuilder(registration);

            services.Add(new ServiceDescriptor(typeof(ISender), builder.Build, lifetime));
            services.SetSenderLookupDescriptor();

            return(builder);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SenderBuilder"/> class.
 /// </summary>
 /// <param name="registration">
 /// The registration delegate that is responsible for creating the <see cref="ISender"/>.
 /// </param>
 public SenderBuilder(SenderRegistration registration) =>