public static void Register(IComponentRegistry registry, IEventStoreConfiguration configuration) { Guard.AgainstNull(registry, nameof(registry)); Guard.AgainstNull(configuration, nameof(configuration)); registry.AttemptRegisterInstance(configuration); registry.RegistryBoostrap(); registry.AttemptRegister <IEventMethodInvokerConfiguration, EventMethodInvokerConfiguration>(); registry.AttemptRegister <IEventMethodInvoker, DefaultEventMethodInvoker>(); registry.AttemptRegister <ISerializer, DefaultSerializer>(); registry.AttemptRegister <IConcurrenyExceptionSpecification, DefaultConcurrenyExceptionSpecification>(); registry.AttemptRegister <IProjectionEventProvider, ProjectionEventProvider>(); registry.AttemptRegister <IProjectionProvider, ProjectionProvider>(); registry.AttemptRegister <ITransactionScopeObserver, TransactionScopeObserver>(); if (!registry.IsRegistered <ITransactionScopeFactory>()) { var transactionScopeConfiguration = configuration.TransactionScope ?? new TransactionScopeConfiguration(); registry.AttemptRegisterInstance <ITransactionScopeFactory>( new DefaultTransactionScopeFactory(transactionScopeConfiguration.Enabled, transactionScopeConfiguration.IsolationLevel, TimeSpan.FromSeconds(transactionScopeConfiguration.TimeoutSeconds))); } registry.AttemptRegister <IPipelineFactory, DefaultPipelineFactory>(); var reflectionService = new ReflectionService(); foreach (var type in reflectionService.GetTypesAssignableTo <IPipeline>(typeof(EventStore).Assembly)) { if (type.IsInterface || type.IsAbstract || registry.IsRegistered(type)) { continue; } registry.Register(type, type, Lifestyle.Transient); } foreach (var type in reflectionService.GetTypesAssignableTo <IPipelineObserver>(typeof(EventStore).Assembly)) { if (type.IsInterface || type.IsAbstract) { continue; } var interfaceType = type.InterfaceMatching($"I{type.Name}"); if (interfaceType != null) { if (registry.IsRegistered(type)) { continue; } registry.Register(interfaceType, type, Lifestyle.Singleton); } else { throw new ApplicationException(string.Format(Resources.ObserverInterfaceMissingException, type.Name)); } } registry.AttemptRegister <IEventStore, EventStore>(); registry.AttemptRegister <IEventProcessor, EventProcessor>(); }
public static void Register(IComponentRegistry registry, IServiceBusConfiguration configuration) { Guard.AgainstNull(registry, nameof(registry)); Guard.AgainstNull(configuration, nameof(configuration)); registry.RegistryBoostrap(); registry.AttemptRegister(configuration); registry.AttemptRegister <IServiceBusEvents, ServiceBusEvents>(); registry.AttemptRegister <ISerializer, DefaultSerializer>(); registry.AttemptRegister <IServiceBusPolicy, DefaultServiceBusPolicy>(); registry.AttemptRegister <IMessageRouteProvider, DefaultMessageRouteProvider>(); registry.AttemptRegister <IIdentityProvider, DefaultIdentityProvider>(); registry.AttemptRegister <IMessageHandlerInvoker, DefaultMessageHandlerInvoker>(); registry.AttemptRegister <IMessageHandlingAssessor, DefaultMessageHandlingAssessor>(); registry.AttemptRegister <IUriResolver, DefaultUriResolver>(); registry.AttemptRegister <IQueueManager, QueueManager>(); registry.AttemptRegister <IWorkerAvailabilityManager, WorkerAvailabilityManager>(); registry.AttemptRegister <ISubscriptionManager, NullSubscriptionManager>(); registry.AttemptRegister <IIdempotenceService, NullIdempotenceService>(); registry.AttemptRegister <ITransactionScopeObserver, TransactionScopeObserver>(); if (!registry.IsRegistered <ITransactionScopeFactory>()) { var transactionScopeConfiguration = configuration.TransactionScope ?? new TransactionScopeConfiguration(); registry.AttemptRegister <ITransactionScopeFactory>( new DefaultTransactionScopeFactory(transactionScopeConfiguration.Enabled, transactionScopeConfiguration.IsolationLevel, TimeSpan.FromSeconds(transactionScopeConfiguration.TimeoutSeconds))); } registry.AttemptRegister <IPipelineFactory, DefaultPipelineFactory>(); registry.AttemptRegister <ITransportMessageFactory, DefaultTransportMessageFactory>(); var reflectionService = new ReflectionService(); foreach (var type in reflectionService.GetTypes <IPipeline>(typeof(ServiceBus).Assembly)) { if (type.IsInterface || type.IsAbstract || registry.IsRegistered(type)) { continue; } registry.Register(type, type, Lifestyle.Transient); } var observers = new List <Type>(); foreach (var type in reflectionService.GetTypes <IPipelineObserver>(typeof(ServiceBus).Assembly)) { if (type.IsInterface || type.IsAbstract) { continue; } var interfaceType = type.InterfaceMatching($"I{type.Name}"); if (interfaceType != null) { if (registry.IsRegistered(type)) { continue; } registry.Register(interfaceType, type, Lifestyle.Singleton); } else { throw new EsbConfigurationException(string.Format(Resources.ObserverInterfaceMissingException, type.Name)); } observers.Add(type); } registry.RegisterCollection(typeof(IPipelineObserver), observers, Lifestyle.Singleton); if (configuration.RegisterHandlers) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in reflectionService.GetTypes(MessageHandlerType, assembly)) { foreach (var @interface in type.GetInterfaces()) { if ([email protected](MessageHandlerType)) { continue; } var genericType = MessageHandlerType.MakeGenericType(@interface.GetGenericArguments()[0]); if (!registry.IsRegistered(genericType)) { registry.Register(genericType, type, Lifestyle.Transient); } } } } } var queueFactoryType = typeof(IQueueFactory); var queueFactoryImplementationTypes = new List <Type>(); void AddQueueFactoryImplementationType(Type type) { if (queueFactoryImplementationTypes.Contains(type)) { return; } queueFactoryImplementationTypes.Add(type); } if (configuration.ScanForQueueFactories) { foreach (var type in new ReflectionService().GetTypes <IQueueFactory>()) { AddQueueFactoryImplementationType(type); } } foreach (var type in configuration.QueueFactoryTypes) { AddQueueFactoryImplementationType(type); } registry.RegisterCollection(queueFactoryType, queueFactoryImplementationTypes, Lifestyle.Singleton); registry.AttemptRegister <IServiceBus, ServiceBus>(); }