Beispiel #1
0
        private static void AddDefaultServices(AddRemotiatrOptions options)
        {
            options.Services.TryAddScoped <IApplicationServiceProviderAccessor, ApplicationServiceProviderAccessor>();

            options.Services.TryAddTransient(typeof(IApplicationService <>), typeof(ApplicationService <>));

            options.Services.AddScoped <IMessageMetadata, MessageMetadata>();

            options.Services.AddSingleton <IMessageHostInfoLookup, MessageHostInfoLookup>();

            ServiceRegistrar.AddRequiredServices(options.Services, new MediatRServiceConfiguration());
        }
Beispiel #2
0
        private static IServiceCollection AddRemotiatr <TMarker, TRemotiatr>(this IServiceCollection serviceCollection, Action <IAddRemotiatrOptions> configure)
            where TRemotiatr : IRemotiatr <TMarker>
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new AddRemotiatrOptions();

            AddDefaultServices(options);

            configure.Invoke(options);

            var internalServiceProvider = options.Services.BuildServiceProvider();

            serviceCollection.RemoveAll <IRemotiatr <TMarker> >();

            if (typeof(TMarker) == typeof(IDefaultRemotiatrMarker))
            {
                serviceCollection.RemoveAll <IRemotiatr>();

                serviceCollection.AddScoped <IRemotiatr>(applicationServices =>
                                                         new DefaultRemotiatr(internalServiceProvider, applicationServices));

                serviceCollection.AddScoped(x => (IRemotiatr <TMarker>)x.GetRequiredService <IRemotiatr>());
            }
            else
            {
                serviceCollection.AddScoped <IRemotiatr <TMarker> >(applicationServices =>
                                                                    new Remotiatr <TMarker>(internalServiceProvider, applicationServices));
            }

            return(serviceCollection);
        }