示例#1
0
        public static MediatorBuilder AddLatransMedaitor(
            this IServiceCollection services,
            Action <IMediatorBuilder>?configure = null
            )
        {
            var builder = new MediatorBuilder();

            services.AddOptions <ActivityExecutionConfigurationOptions>();
            services.AddTransient <ActivityExecutionConfigurationDefaults>();
            services.AddScoped <ILocalDisposables, LocalDisposables>();
            services.AddScoped <IMediatorClientFactory, MediatorClientFactory>();
            services.AddTransient <IMediatorClient, MediatorClient>();
            services.AddSingleton <IMediatorService>((serviceProvider) => {
                IMediatorService result;
                lock (serviceProvider) {
                    builder.Build();
                    var options = builder.GetOptions();
                    result      = new MediatorService(options);
                }
                return(result);
            });
            if (configure is object)
            {
                configure(builder);
            }
            return(builder);
        }