/// <summary> /// Registers a new dependency/implementation type pair as a singleton if the dependency has not yet been registered; /// else does nothing. /// </summary> /// <typeparam name="TDependencyImplementation"> /// The type of the dependency, that is also the implementation, being /// registered. /// </typeparam> /// <param name="registry">The `IComponentRegistry` instance to register the mapping against.</param> public static IComponentRegistry AttemptRegister <TDependencyImplementation>(this IComponentRegistry registry) where TDependencyImplementation : class { return(registry.IsRegistered <TDependencyImplementation>() ? registry : registry.Register <TDependencyImplementation>(Lifestyle.Singleton)); }
/// <summary> /// Register all interfaces that are not yet registered in the given assembly that have a single implementation as a /// regular dependency. /// All interfaces that have more than 1 implementation are registered as collections. /// </summary> /// <param name="registry">The `IComponentRegistry` instance to register the mapping against.</param> /// <param name="assembly">The assembly that contains the types to evaluate.</param> /// <param name="lifestyle">The `Lifestyle` to register the dependency as.</param> public static void RegisterAll(this IComponentRegistry registry, Assembly assembly, Lifestyle lifestyle = Lifestyle.Singleton) { Guard.AgainstNull(registry, nameof(registry)); Guard.AgainstNull(assembly, nameof(assembly)); Type FindDependencyType(Type type) { var interfaces = type.GetInterfaces(); if (interfaces.Length == 0) { return(null); } return(interfaces.FirstOrDefault(item => item.Name.Equals($"I{type.Name}")) ?? interfaces.First()); } Register( registry, assembly, type => { var dependencyType = FindDependencyType(type); return(dependencyType != null && !registry.IsRegistered(dependencyType)); }, FindDependencyType, type => lifestyle); }
public void Register(IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (!registry.IsRegistered <IRabbitMQConfiguration>()) { registry.Register <IRabbitMQConfiguration, RabbitMQConfiguration>(); } }
public static void RegisterActiveTimeRange(this IComponentRegistry registry) { if (!registry.IsRegistered <IActiveTimeRangeConfiguration>()) { registry.AttemptRegisterInstance(ActiveTimeRangeSection.Configuration()); } registry.AttemptRegister <ActiveTimeRangeModule>(); }
public static IComponentRegistry AttemptRegisterComponentResolverDelegate(this IComponentRegistry registry) { if (!registry.IsRegistered <IComponentResolver>()) { Log.Information(Resources.ComponentResolverDelegateRegistered); registry.AttemptRegisterInstance <IComponentResolver>(new ComponentResolverDelegate()); } return(registry); }
public static void RegisterCorruptTransportMessage(this IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (!registry.IsRegistered <ICorruptTransportMessageConfiguration>()) { registry.AttemptRegisterInstance(CorruptTransportMessageSection.Configuration()); } registry.AttemptRegister <CorruptTransportMessageModule>(); }
public void Register(IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (!registry.IsRegistered <IOpswatConfiguration>()) { registry.RegisterInstance(OpswatSection.Configuration()); } registry.AttemptRegister <IOpswatApi, OpswatApi>(); registry.AttemptRegister <IMalwareService, OpswatMalwareService>(); }
public static void RegisterMessageForwarding(this IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (!registry.IsRegistered <IMessageForwardingConfiguration>()) { registry.AttemptRegisterInstance(MessageForwardingSection.Configuration()); } registry.AttemptRegister <MessageForwardingModule>(); registry.AttemptRegister <MessageForwardingObserver>(); }
/// <summary> /// Registers an open generic for the given dependency type if the dependency has not yet been registered; else /// does nothing. /// </summary> /// <param name="registry">The `IComponentRegistry` instance to register the mapping against.</param> /// <param name="dependencyType">The open generic type of the dependency being registered.</param> /// <param name="implementationType">The open generic type of the implementation that should be resolved.</param> /// <param name="lifestyle">The lifestyle of the component.</param> public static IComponentRegistry AttemptRegisterGeneric(this IComponentRegistry registry, Type dependencyType, Type implementationType, Lifestyle lifestyle) { Guard.AgainstNull(registry, nameof(registry)); if (registry.IsRegistered(dependencyType)) { return(registry); } registry.RegisterGeneric(dependencyType, implementationType, lifestyle); return(registry); }
/// <summary> /// Registers a singleton instance for the given dependency type if the dependency has not yet been registered; else /// does nothing. /// </summary> /// <typeparam name="TDependency">The type of the dependency being registered.</typeparam> /// <param name="registry">The registry instance to register the mapping against.</param> /// <param name="instance">The singleton instance to be registered.</param> public static IComponentRegistry AttemptRegister <TDependency>(this IComponentRegistry registry, TDependency instance) { Guard.AgainstNull(registry, "registry"); if (registry.IsRegistered <TDependency>()) { return(registry); } registry.Register(typeof(TDependency), instance); return(registry); }
public static void RegisterIdempotence(this IComponentRegistry registry) { Guard.AgainstNull(registry, "registry"); registry.AttemptRegister <IScriptProviderConfiguration, ScriptProviderConfiguration>(); registry.AttemptRegister <IScriptProvider, ScriptProvider>(); if (!registry.IsRegistered <IIdempotenceConfiguration>()) { registry.RegisterInstance <IIdempotenceConfiguration>(IdempotenceSection.Configuration()); } registry.AttemptRegister <IIdempotenceService, IdempotenceService>(); }
/// <summary> /// Registers a new dependency/implementation type pair if the dependency has not yet been registered; else does /// nothing. /// </summary> /// <typeparam name="TDependencyImplementation"> /// The type of the dependency, that is also the implementation, being /// registered. /// </typeparam> /// <param name="registry">The registry instance to register the mapping against.</param> /// <param name="lifestyle">The lifestyle of the component.</param> public static IComponentRegistry AttemptRegister <TDependencyImplementation>(this IComponentRegistry registry, Lifestyle lifestyle) where TDependencyImplementation : class { Guard.AgainstNull(registry, "registry"); if (registry.IsRegistered <TDependencyImplementation>()) { return(registry); } registry.Register(typeof(TDependencyImplementation), typeof(TDependencyImplementation), lifestyle); return(registry); }
/// <summary> /// Registers a new dependency/implementation type pair as a singleton if the dependency has not yet been registered; /// else does nothing. /// </summary> /// <typeparam name="TDependency">The type of the dependency being registered.</typeparam> /// <typeparam name="TImplementation">The type of the implementation that should be resolved.</typeparam> /// <param name="registry">The registry instance to register the mapping against.</param> public static IComponentRegistry AttemptRegister <TDependency, TImplementation>(this IComponentRegistry registry) where TDependency : class where TImplementation : class, TDependency { Guard.AgainstNull(registry, "registry"); if (registry.IsRegistered <TDependency>()) { return(registry); } registry.Register <TDependency, TImplementation>(Lifestyle.Singleton); return(registry); }
public void Register(IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (_registryBootstrapCalled) { return; } _registryBootstrapCalled = true; if (!registry.IsRegistered <ISentinelConfiguration>()) { registry.AttemptRegisterInstance(SentinelSection.Configuration()); } registry.AttemptRegister <ISentinelObserver, SentinelObserver>(); registry.AttemptRegister <IEndpointAggregator, EndpointAggregator>(); registry.AttemptRegister <SentinelModule>(); }
public static void RegisterEventProcessing(this IComponentRegistry registry) { Guard.AgainstNull(registry, nameof(registry)); if (!registry.IsRegistered <IProjectionConfiguration>()) { registry.AttemptRegisterInstance <IProjectionConfiguration>(ProjectionSection.Configuration(new ConnectionConfigurationProvider())); } registry.AttemptRegister <IScriptProviderConfiguration, ScriptProviderConfiguration>(); registry.AttemptRegister <IScriptProvider, ScriptProvider>(); registry.AttemptRegister <IDatabaseContextCache, ThreadStaticDatabaseContextCache>(); registry.AttemptRegister <IDatabaseContextFactory, DatabaseContextFactory>(); registry.AttemptRegister <IDbConnectionFactory, DbConnectionFactory>(); registry.AttemptRegister <IDbCommandFactory, DbCommandFactory>(); registry.AttemptRegister <IDatabaseGateway, DatabaseGateway>(); registry.AttemptRegister <IQueryMapper, QueryMapper>(); registry.AttemptRegister <IProjectionRepository, ProjectionRepository>(); registry.AttemptRegister <IProjectionQueryFactory, ProjectionQueryFactory>(); registry.AttemptRegister <EventProcessingObserver, EventProcessingObserver>(); registry.AttemptRegister <EventProcessingModule, EventProcessingModule>(); }
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>(); }
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>(); }
/// <summary> /// Determines whether the component registry has a dependency of the given type registered. /// </summary> /// <typeparam name="TDependency">The type of the dependency that is being checked.</typeparam> /// <param name="registry">The registry instance to register the mapping against.</param> /// <returns>Returns `true` if the dependency type is registered; else `false`.</returns> public static bool IsRegistered <TDependency>(this IComponentRegistry registry) { Guard.AgainstNull(registry, "registry"); return(registry.IsRegistered(typeof(TDependency))); }
public bool IsRegistered(Service service) { return(_registry.IsRegistered(service)); }