Example #1
0
 private static void RegisterElasticsearchReadStore <TReadModel>(
     IServiceRegistration serviceRegistration)
     where TReadModel : class, IReadModel
 {
     serviceRegistration.Register <IElasticsearchReadModelStore <TReadModel>, ElasticsearchReadModelStore <TReadModel> >();
     serviceRegistration.Register <IReadModelStore <TReadModel> >(r => r.Resolver.Resolve <IElasticsearchReadModelStore <TReadModel> >());
 }
Example #2
0
 private static void RegisterStreamsDbReadStore <TReadModel>(
     IServiceRegistration serviceRegistration)
     where TReadModel : class, IReadModel
 {
     serviceRegistration.Register <IStreamsDbReadModelStore <TReadModel>, StreamsDbReadModelStore <TReadModel> >();
     serviceRegistration.Register <IReadModelStore <TReadModel> >(r => r.Resolver.Resolve <IStreamsDbReadModelStore <TReadModel> >());
 }
Example #3
0
 private static void RegisterInMemoryReadStore <TReadModel>(
     IServiceRegistration serviceRegistration)
     where TReadModel : class, IReadModel
 {
     serviceRegistration.Register <IInMemoryReadStore <TReadModel>, InMemoryReadStore <TReadModel> >(Lifetime.Singleton);
     serviceRegistration.Register <IReadModelStore <TReadModel> >(r => r.Resolver.Resolve <IInMemoryReadStore <TReadModel> >());
     serviceRegistration.Register <IQueryHandler <InMemoryQuery <TReadModel>, IReadOnlyCollection <TReadModel> >, InMemoryQueryHandler <TReadModel> >();
 }
 private static void RegisterMssqlReadStore <TReadModel>(
     IServiceRegistration serviceRegistration)
     where TReadModel : class, IReadModel
 {
     serviceRegistration.Register <IReadModelSqlGenerator, ReadModelSqlGenerator>(Lifetime.Singleton, true);
     serviceRegistration.Register <IMssqlReadModelStore <TReadModel>, MssqlReadModelStore <TReadModel> >();
     serviceRegistration.Register <IReadModelStore <TReadModel> >(r => r.Resolver.Resolve <IMssqlReadModelStore <TReadModel> >());
 }
        /// <summary>
        /// Scan and Register services using the specified <paramref name="builder"/> for the specified <paramref name="lifetime"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
        /// <param name="builder">The builder delegate used to scan and register services</param>
        /// <param name="lifetime">The service lifetime.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IServiceRegistration Register(this IServiceRegistration services, Action <IServiceRegistrationBuilder> builder, ServiceLifetime lifetime)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var types = services.ServiceContext.Types;

            var serviceBuilder = new ServiceRegistrationBuilder(types);

            builder(serviceBuilder);

            var mapping = serviceBuilder.TypeMaps;

            foreach (var typeMap in mapping)
            {
                foreach (var serviceType in typeMap.ServiceTypes)
                {
                    services.Register(serviceType, typeMap.ImplementationType, lifetime);
                }
            }

            return(services);
        }
Example #6
0
        /// <summary>
        /// Registers the services used by serialization.
        /// </summary>
        /// <param name="registration">The <see cref="IServiceRegistration"/> to register with.</param>
        public void RegisterDefaultServices(IServiceRegistration registration)
        {
            registration.RegisterSingleton <IReflectionHelper>(
                new ReflectionHelper());
            registration.Register <IConfigurationBuilder, ConfigurationBuilder>();
            registration.RegisterSingleton <IDefaultConfiguration>(new DefaultConfiguration());
            var rules = new RulesEngine();

            registration.RegisterSingleton <IRulesEngine>(rules);
            registration.RegisterSingleton <IRulesConfiguration>(rules);
            registration.RegisterSingleton <IAnonymousTypeAdapter>(new AnonymousTypeAdapter());
        }
        /// <summary>
        /// Registers a transient service of the type specified in <paramref name="serviceType"/> with a
        /// factory specified in <paramref name="implementationFactory"/> to the
        /// specified <see cref="IServiceRegistration"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
        /// <param name="serviceType">The type of the service to register.</param>
        /// <param name="implementationFactory">The factory that creates the service.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <seealso cref="ServiceLifetime.Transient"/>
        public static IServiceRegistration RegisterTransient(this IServiceRegistration services, Type serviceType, Func <IServiceProvider, object> implementationFactory)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            return(services.Register(serviceType, implementationFactory, ServiceLifetime.Transient));
        }
        /// <summary>
        /// Registers a singleton service of the type specified in <paramref name="serviceType"/> with an
        /// instance specified in <paramref name="implementationInstance"/> to the
        /// specified <see cref="IServiceRegistration"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
        /// <param name="serviceType">The type of the service to register.</param>
        /// <param name="implementationInstance">The instance of the service.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <seealso cref="ServiceLifetime.Singleton"/>
        public static IServiceRegistration RegisterSingleton(this IServiceRegistration services, Type serviceType, object implementationInstance)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            return(services.Register(serviceType, p => implementationInstance, ServiceLifetime.Singleton));
        }
        /// <summary>
        /// Registers a scoped service of the type specified in <paramref name="serviceType"/> with an
        /// implementation of the type specified in <paramref name="implementationType"/> to the
        /// specified <see cref="IServiceRegistration"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
        /// <param name="serviceType">The type of the service to register.</param>
        /// <param name="implementationType">The implementation type of the service.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <seealso cref="ServiceLifetime.Scoped"/>
        public static IServiceRegistration RegisterScoped(this IServiceRegistration services, Type serviceType, Type implementationType)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            return(services.Register(serviceType, implementationType, ServiceLifetime.Scoped));
        }
Example #10
0
        /// <summary>
        /// Registers the services used by serialization.
        /// </summary>
        /// <param name="registration">The <see cref="IServiceRegistration"/> to register with.</param>
        public void RegisterDefaultServices(IServiceRegistration registration)
        {
            registration.RegisterSingleton <IReflectionHelper>(
                new ReflectionHelper());
            registration.Register <IConfigurationBuilder, ConfigurationBuilder>();
            registration.RegisterSingleton <IDefaultConfiguration>(new DefaultConfiguration());
            var rules = new RulesEngine
            {
                LoadingDefaults = true,
            };

            registration.RegisterSingleton <IRulesEngine>(rules);
            registration.RegisterSingleton <IRulesConfiguration>(rules);
            registration.RegisterSingleton <IAnonymousTypeAdapter>(
                new AnonymousTypeAdapter());
            registration.RegisterSingleton <ITypesCompressor>(
                new TypesCompressor());
            registration.RegisterSingleton <ISerializationWrapper <string, JsonSerializerOptions, JsonSerializerOptions> >(
                new JsonWrapper());
        }
Example #11
0
        public MediatorConfiguration UseMiddleware <TMiddleware>()
            where TMiddleware : IMiddleware
        {
            var middlewareType = typeof(TMiddleware);

            if (!MiddlewareTypes.Contains(middlewareType))
            {
                MiddlewareTypes.Add(middlewareType);

                _serviceRegistration.Register(middlewareType);
            }

            return(UseMiddleware(next =>
            {
                return async message =>
                {
                    await((IMiddleware)Resolver.Resolve(middlewareType)).InvokeAsync(message, next);
                };
            }));
        }
Example #12
0
 public void Register <TCommand>(Handler <TAgg, TId, TState, TCommand> handler)
     where TCommand : ICommand <TAgg, TId, IExecutionResult>
 {
     _services.Register(c => _commandHandlerFactory.CreateHandler(handler, c));
 }
Example #13
0
        private void RegisterDefaults(IServiceRegistration serviceRegistration)
        {
            serviceRegistration.Register <ILog, ConsoleLog>();
            serviceRegistration.Register <IAggregateStoreResilienceStrategy, NoAggregateStoreResilienceStrategy>();
            serviceRegistration.Register <IDispatchToReadStoresResilienceStrategy, NoDispatchToReadStoresResilienceStrategy>();
            serviceRegistration.Register <ISagaUpdateResilienceStrategy, NoSagaUpdateResilienceStrategy>();
            serviceRegistration.Register <IDispatchToSubscriberResilienceStrategy, NoDispatchToSubscriberResilienceStrategy>();
            serviceRegistration.Register <IDispatchToReadStores, DispatchToReadStores>();
            serviceRegistration.Register <IEventStore, EventStoreBase>();
            serviceRegistration.Register <IEventPersistence, InMemoryEventPersistence>(Lifetime.Singleton);
            serviceRegistration.Register <ICommandBus, CommandBus>();
            serviceRegistration.Register <IAggregateStore, AggregateStore>();
            serviceRegistration.Register <ISnapshotStore, SnapshotStore>();
            serviceRegistration.Register <ISnapshotSerilizer, SnapshotSerilizer>();
            serviceRegistration.Register <ISnapshotPersistence, NullSnapshotPersistence>();
            serviceRegistration.Register <ISnapshotUpgradeService, SnapshotUpgradeService>();
            serviceRegistration.Register <ISnapshotDefinitionService, SnapshotDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IReadModelPopulator, ReadModelPopulator>();
            serviceRegistration.Register <IEventJsonSerializer, EventJsonSerializer>();
            serviceRegistration.Register <IEventDefinitionService, EventDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IQueryProcessor, QueryProcessor>();
            serviceRegistration.Register <IJsonSerializer, JsonSerializer>(Lifetime.Singleton);
            serviceRegistration.Register <IJsonOptions, JsonOptions>();
            serviceRegistration.Register <IJobScheduler, InstantJobScheduler>();
            serviceRegistration.Register <IJobRunner, JobRunner>();
            serviceRegistration.Register <IJobDefinitionService, JobDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IOptimisticConcurrencyRetryStrategy, OptimisticConcurrencyRetryStrategy>();
            serviceRegistration.Register <IEventUpgradeManager, EventUpgradeManager>(Lifetime.Singleton);
            serviceRegistration.Register <IAggregateFactory, AggregateFactory>();
            serviceRegistration.Register <IReadModelDomainEventApplier, ReadModelDomainEventApplier>();
            serviceRegistration.Register <IDomainEventPublisher, DomainEventPublisher>();
            serviceRegistration.Register <ISerializedCommandPublisher, SerializedCommandPublisher>();
            serviceRegistration.Register <ICommandDefinitionService, CommandDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IDispatchToEventSubscribers, DispatchToEventSubscribers>();
            serviceRegistration.Register <IDomainEventFactory, DomainEventFactory>(Lifetime.Singleton);
            serviceRegistration.Register <ISagaDefinitionService, SagaDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <ISagaStore, SagaAggregateStore>();
            serviceRegistration.Register <ISagaErrorHandler, SagaErrorHandler>();
            serviceRegistration.Register <Func <Type, ISagaErrorHandler> >(context => sagaType =>
            {
                Type genericSagaErrorHandlerType = typeof(ISagaErrorHandler <>);
                Type typeToResolve = genericSagaErrorHandlerType.MakeGenericType(sagaType);
                if (context.Resolver.GetRegisteredServices().Any(rs => rs == typeToResolve))
                {
                    return((ISagaErrorHandler)context.Resolver.Resolve(typeToResolve));
                }
                return(null);
            });
            serviceRegistration.Register <IDispatchToSagas, DispatchToSagas>();
#if NET452
            serviceRegistration.Register <IMemoryCache, MemoryCache>(Lifetime.Singleton);
#else
            serviceRegistration.Register <IMemoryCache, DictionaryMemoryCache>(Lifetime.Singleton);
#endif
            serviceRegistration.RegisterGeneric(typeof(ISagaUpdater <, , ,>), typeof(SagaUpdater <, , ,>));
            serviceRegistration.Register <IEventFlowConfiguration>(_ => _eventFlowConfiguration);
            serviceRegistration.Register <ICancellationConfiguration>(_ => _eventFlowConfiguration);
            serviceRegistration.RegisterGeneric(typeof(ITransientFaultHandler <>), typeof(TransientFaultHandler <>));
            serviceRegistration.RegisterGeneric(typeof(IReadModelFactory <>), typeof(ReadModelFactory <>), Lifetime.Singleton);
            serviceRegistration.Register <IBootstrap, DefinitionServicesInitilizer>();
            serviceRegistration.Register(_ => ModuleRegistration, Lifetime.Singleton);
            serviceRegistration.Register <ILoadedVersionedTypes>(r => new LoadedVersionedTypes(
                                                                     _jobTypes,
                                                                     _commandTypes,
                                                                     _aggregateEventTypes,
                                                                     _sagaTypes,
                                                                     _snapshotTypes),
                                                                 Lifetime.Singleton);
        }
 void IEntityFrameworkConfiguration.Apply(IServiceRegistration serviceRegistration)
 {
     serviceRegistration.Register <IEntityFrameworkConfiguration>(s => this);
     _registerUniqueConstraintDetectionStrategy(serviceRegistration);
     _registerBulkOperationConfiguration(serviceRegistration);
 }
 /// <summary>
 /// Scan and Register singleton services using the specified <paramref name="builder"/>.
 /// </summary>
 /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
 /// <param name="builder">The builder delegate used to scan and register services</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceRegistration RegisterSingleton(this IServiceRegistration services, Action <IServiceRegistrationBuilder> builder)
 {
     return(services.Register(builder, ServiceLifetime.Singleton));
 }
Example #16
0
        private void RegisterDefaults(IServiceRegistration serviceRegistration)
        {
            // http://docs.autofac.org/en/latest/register/registration.html
            // Maybe swap around and do after and and .PreserveExistingDefaults()

            serviceRegistration.Register <ILog, ConsoleLog>();
            serviceRegistration.Register <IEventStore, EventStoreBase>();
            serviceRegistration.Register <IEventPersistence, InMemoryEventPersistence>(Lifetime.Singleton);
            serviceRegistration.Register <ICommandBus, CommandBus>();
            serviceRegistration.Register <IReadModelPopulator, ReadModelPopulator>();
            serviceRegistration.Register <IEventJsonSerializer, EventJsonSerializer>();
            serviceRegistration.Register <IEventDefinitionService, EventDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IQueryProcessor, QueryProcessor>(Lifetime.Singleton);
            serviceRegistration.Register <IJsonSerializer, JsonSerializer>();
            serviceRegistration.Register <IJobScheduler, InstantJobScheduler>();
            serviceRegistration.Register <IJobRunner, JobRunner>();
            serviceRegistration.Register <IJobDefinitionService, JobDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IOptimisticConcurrencyRetryStrategy, OptimisticConcurrencyRetryStrategy>();
            serviceRegistration.Register <IEventUpgradeManager, EventUpgradeManager>(Lifetime.Singleton);
            serviceRegistration.Register <IAggregateFactory, AggregateFactory>();
            serviceRegistration.Register <IReadModelDomainEventApplier, ReadModelDomainEventApplier>();
            serviceRegistration.Register <IDomainEventPublisher, DomainEventPublisher>();
            serviceRegistration.Register <ISerializedCommandPublisher, SerializedCommandPublisher>();
            serviceRegistration.Register <ICommandDefinitionService, CommandDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IDispatchToEventSubscribers, DispatchToEventSubscribers>();
            serviceRegistration.Register <IDomainEventFactory, DomainEventFactory>(Lifetime.Singleton);
            serviceRegistration.Register <IEventFlowConfiguration>(_ => _eventFlowConfiguration);
            serviceRegistration.RegisterGeneric(typeof(ITransientFaultHandler <>), typeof(TransientFaultHandler <>));
            serviceRegistration.Register <IBootstrap, DefinitionServicesInitilizer>();
            serviceRegistration.Register(_ => ModuleRegistration, Lifetime.Singleton);
            serviceRegistration.Register <ILoadedVersionedTypes>(r => new LoadedVersionedTypes(
                                                                     _jobTypes,
                                                                     _commandTypes,
                                                                     _aggregateEventTypes),
                                                                 Lifetime.Singleton);
        }
 /// <summary>
 ///     Registers the defaults.
 /// </summary>
 /// <param name="serviceRegistration">The service registration.</param>
 private void RegisterDefaults(IServiceRegistration serviceRegistration)
 {
     serviceRegistration.Register(_ => ModuleRegistration, Lifetime.Singleton);
 }
Example #18
0
        private void RegisterDefaults(IServiceRegistration serviceRegistration)
        {
            serviceRegistration.Register <ILog, ConsoleLog>();
            serviceRegistration.Register <IEventStore, EventStoreBase>();
            serviceRegistration.Register <IEventPersistence, InMemoryEventPersistence>(Lifetime.Singleton);
            serviceRegistration.Register <ICommandBus, CommandBus>();
            serviceRegistration.Register <IAggregateStore, AggregateStore>();
            serviceRegistration.Register <ISnapshotStore, SnapshotStore>();
            serviceRegistration.Register <ISnapshotSerilizer, SnapshotSerilizer>();
            serviceRegistration.Register <ISnapshotPersistence, NullSnapshotPersistence>();
            serviceRegistration.Register <ISnapshotUpgradeService, SnapshotUpgradeService>();
            serviceRegistration.Register <ISnapshotDefinitionService, SnapshotDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IReadModelPopulator, ReadModelPopulator>();
            serviceRegistration.Register <IEventJsonSerializer, EventJsonSerializer>();
            serviceRegistration.Register <IEventDefinitionService, EventDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IQueryProcessor, QueryProcessor>();
            serviceRegistration.Register <IJsonSerializer, JsonSerializer>();
            serviceRegistration.Register <IJobScheduler, InstantJobScheduler>();
            serviceRegistration.Register <IJobRunner, JobRunner>();
            serviceRegistration.Register <IJobDefinitionService, JobDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IOptimisticConcurrencyRetryStrategy, OptimisticConcurrencyRetryStrategy>();
            serviceRegistration.Register <IEventUpgradeManager, EventUpgradeManager>(Lifetime.Singleton);
            serviceRegistration.Register <IAggregateFactory, AggregateFactory>();
            serviceRegistration.Register <IReadModelDomainEventApplier, ReadModelDomainEventApplier>();
            serviceRegistration.Register <IDomainEventPublisher, DomainEventPublisher>();
            serviceRegistration.Register <ISerializedCommandPublisher, SerializedCommandPublisher>();
            serviceRegistration.Register <ICommandDefinitionService, CommandDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <IDispatchToEventSubscribers, DispatchToEventSubscribers>();
            serviceRegistration.Register <IDomainEventFactory, DomainEventFactory>(Lifetime.Singleton);
            serviceRegistration.Register <ISagaDefinitionService, SagaDefinitionService>(Lifetime.Singleton);
            serviceRegistration.Register <ISagaStore, SagaAggregateStore>();
            serviceRegistration.Register <ISagaErrorHandler, SagaErrorHandler>();
            serviceRegistration.Register <IDispatchToSagas, DispatchToSagas>();
#if NET451
            serviceRegistration.Register <IMemoryCache, MemoryCache>(Lifetime.Singleton);
#else
            serviceRegistration.Register <IMemoryCache, DictionaryMemoryCache>(Lifetime.Singleton);
#endif
            serviceRegistration.RegisterGeneric(typeof(ISagaUpdater <, , ,>), typeof(SagaUpdater <, , ,>));
            serviceRegistration.Register <IEventFlowConfiguration>(_ => _eventFlowConfiguration);
            serviceRegistration.Register <ICancellationConfiguration>(_ => _eventFlowConfiguration);
            serviceRegistration.RegisterGeneric(typeof(ITransientFaultHandler <>), typeof(TransientFaultHandler <>));
            serviceRegistration.RegisterGeneric(typeof(IReadModelFactory <>), typeof(ReadModelFactory <>), Lifetime.Singleton);
            serviceRegistration.Register <IBootstrap, DefinitionServicesInitilizer>();
            serviceRegistration.Register(_ => ModuleRegistration, Lifetime.Singleton);
            serviceRegistration.Register <ILoadedVersionedTypes>(r => new LoadedVersionedTypes(
                                                                     _jobTypes,
                                                                     _commandTypes,
                                                                     _aggregateEventTypes,
                                                                     _sagaTypes,
                                                                     _snapshotTypes),
                                                                 Lifetime.Singleton);
        }
 /// <summary>
 /// Scan and Register transient services using the specified builder.
 /// </summary>
 /// <param name="services">The <see cref="IServiceRegistration"/> to add the service to.</param>
 /// <param name="builder">The builder delegate used to scan and register services</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IServiceRegistration RegisterTransient(this IServiceRegistration services, Action <IServiceRegistrationBuilder> builder)
 {
     return(services.Register(builder, ServiceLifetime.Transient));
 }