private static ICommandingDependencyResolver Register <TSerializer>(this ICommandingDependencyResolver dependencyResolver) where TSerializer : IAzureStorageQueueSerializer { dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, TSerializer>(); dependencyResolver.TypeMapping <IAzureStorageCommandQueueProcessorFactory, AzureStorageCommandQueueProcessorFactory>(); dependencyResolver.TypeMapping <IAzureStorageQueueDispatcherFactory, AzureStorageQueueDispatcherFactory>(); return(dependencyResolver); }
/// <summary> /// Registers a command auditor that writes to an event hub /// </summary> /// <param name="resolver">Dependency resolver</param> /// <param name="eventHubClient">The event hub client</param> /// <param name="partitionKeyProvider">An optional partition key provider, if unspecified events will be sent unpartitioned</param> /// <param name="options">Options for the event hub auditor configuration</param> /// <returns>Dependency resolver</returns> public static ICommandingDependencyResolver UseEventHubCommandAuditing(this ICommandingDependencyResolver resolver, Microsoft.Azure.EventHubs.EventHubClient eventHubClient, IPartitionKeyProvider partitionKeyProvider = null, AzureEventHubAuditorOptions options = null) { options = options ?? new AzureEventHubAuditorOptions(); IEventHubClient client = new EventHubClient(eventHubClient); if (partitionKeyProvider == null) { partitionKeyProvider = new NullPartitionKeyProvider(); } resolver.RegisterInstance(client); resolver.RegisterInstance(partitionKeyProvider); resolver.TypeMapping <IAuditItemMapper, AuditItemMapper>(); resolver.TypeMapping <IEventHubSerializer, EventHubSerializer>(); if (options.UsePreDispatchAuditor) { resolver.UsePreDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPreDispatchRootOnly); } if (options.UsePostDispatchAuditor) { resolver.UsePostDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPostDispatchRootOnly); } if (options.UseExecutionAuditor) { resolver.UseExecutionCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditExecuteDispatchRootOnly); } return(resolver); }
private static ICommandingDependencyResolver Register <TSerializer>(ICommandingDependencyResolver dependencyResolver, HttpClient client) where TSerializer : IHttpCommandSerializer { HttpClientProvider = client == null ? new HttpClientProvider() : new HttpClientProvider(client); dependencyResolver.RegisterInstance(HttpClientProvider); dependencyResolver.TypeMapping <IHttpCommandSerializer, TSerializer>(); dependencyResolver.TypeMapping <IUriCommandQueryBuilder, UriCommandQueryBuilder>(); dependencyResolver.TypeMapping <IHttpCommandDispatcherFactory, HttpCommandDispatcherFactory>(); return(dependencyResolver); }
public static ICommandingDependencyResolver UseAzureStorageAuditQueueProcessor(this ICommandingDependencyResolver dependencyResolver, CloudQueue queue, CloudQueue deadLetterQueue = null) { ICloudAuditQueueProvider cloudAuditQueueProvider = new CloudAuditQueueProvider(queue, deadLetterQueue); dependencyResolver.RegisterInstance(cloudAuditQueueProvider); dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, AzureStorageQueueSerializer>(); dependencyResolver.TypeMapping <IAzureStorageAuditQueueProcessorFactory, AzureStorageAuditQueueProcessorFactory>(); return(dependencyResolver); }
public static ICommandingDependencyResolver UseQueues(this ICommandingDependencyResolver dependencyResolver, Action <string, ICommand, Exception> logError = null, Action <string, ICommand, Exception> logWarning = null, Action <string, ICommand, Exception> logInfo = null) { ICommandQueueProcessorLogger logger = new CommandQueueProcessorLogger(logWarning, logError, logInfo); dependencyResolver.RegisterInstance(logger); dependencyResolver.TypeMapping <IAsynchronousBackoffPolicyFactory, AsynchronousBackoffPolicyFactory>(); dependencyResolver.TypeMapping <ICommandQueueProcessor, CommandQueueProcessor>(); return(dependencyResolver); }
public static ICommandingDependencyResolver UseAzureStorageCommandAuditing(this ICommandingDependencyResolver dependencyResolver, CloudQueue queue, CloudBlobContainer blobContainer = null, IStorageStrategy storageStrategy = null, AzureStorageAuditorOptions options = null) { options = options ?? new AzureStorageAuditorOptions(); ICloudAuditQueueProvider cloudAuditQueueProvider = new CloudAuditQueueProvider(queue, null); ICloudAuditQueueBlobContainerProvider cloudAuditQueueBlobContainerProvider = new CloudAuditQueueBlobContainerProvider(blobContainer); dependencyResolver.RegisterInstance(cloudAuditQueueProvider); dependencyResolver.RegisterInstance(cloudAuditQueueBlobContainerProvider); dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, AzureStorageQueueSerializer>(); if (options.UsePreDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePreDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPreDispatchRootOnly); } if (options.UsePostDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePostDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPostDispatchRootOnly); } if (options.UseExecutionAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UseExecutionCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditExecuteDispatchRootOnly); } return(dependencyResolver); }
/// <summary> /// Sets up the cache with the specified cache key provider /// </summary> /// <param name="resolver">The dependency resolver</param> /// <param name="cacheKeyProvider">Instance of a cache key provider</param> /// <param name="replaceDefaultCommandDispatcher">If true then the default ICommandDispatcher will be replaced with the caching variant</param> /// <param name="options">Cache options</param> /// <returns>The dependency resolver</returns> public static ICommandingDependencyResolver UseCommandCache( this ICommandingDependencyResolver resolver, ICacheKeyProvider cacheKeyProvider, bool replaceDefaultCommandDispatcher, params CacheOptions[] options) { ICacheOptionsProvider cacheOptionsProvider = new CacheOptionsProvider(options); resolver.RegisterInstance(cacheOptionsProvider); if (replaceDefaultCommandDispatcher) { resolver.TypeMapping <ICommandDispatcher, CachedCommandDispatcher>(); } else { resolver.TypeMapping <ICachedCommandDispatcher, CachedCommandDispatcher>(); } resolver.RegisterInstance(cacheKeyProvider); return(resolver); }
public ICommandingDependencyResolver UseAuditItemEnricher <TAuditItemEnricher>(ICommandingDependencyResolver commandingDependencyResolver) where TAuditItemEnricher : IAuditItemEnricher { lock (_auditItemEnricherPipelineLockObject) { if (_auditItemEnricherPipeline == null) { throw new AuditConfigurationException("The commanding system must be initialised with the UseCommanding method before any registering any audit item enrichers"); } _auditItemEnricherPipeline.AddEnricher <TAuditItemEnricher>(); } commandingDependencyResolver.TypeMapping <TAuditItemEnricher, TAuditItemEnricher>(); return(commandingDependencyResolver); }
public ICommandingDependencyResolver UseExecutionCommandingAuditor <TExecutionAuditorImpl>( ICommandingDependencyResolver dependencyResolver, bool auditRootCommandOnly = true) where TExecutionAuditorImpl : ICommandAuditor { lock (_auditorPipelineLockObject) { if (_auditorPipeline == null) { throw new AuditConfigurationException("The commanding system must be initialised with the UseCommanding method before any registering any auditors"); } IAuditorRegistration registration = (IAuditorRegistration)_auditorPipeline; registration.RegisterExecutionAuditor <TExecutionAuditorImpl>(auditRootCommandOnly); } dependencyResolver.TypeMapping <TExecutionAuditorImpl, TExecutionAuditorImpl>(); return(dependencyResolver); }
public static ICommandingDependencyResolver UseCommandMemoryCache(this ICommandingDependencyResolver resolver) { resolver.TypeMapping <ICacheAdapter, MemoryCacheAdapter>(); return(resolver); }
public ICommandRegistry UseCommanding(ICommandingDependencyResolver dependencyResolver, IOptions options = null) { options = options ?? new Options(); dependencyResolver.AssociatedCommandingRuntime = this; ICommandHandlerExecuter commandHandlerExecuter = new CommandHandlerExecuter(); dependencyResolver.RegisterInstance(commandHandlerExecuter); IOptionsProvider optionsProvider = new OptionsProvider(options); dependencyResolver.RegisterInstance(optionsProvider); // the registry is always shared, but vagaries of different IoC containers mean its dangerous to rely // on dependecy resolver checks for an existing registration lock (_registryLockObject) { if (_registry == null || options.Reset) { Action <Type> resolverContainerRegistration = type => dependencyResolver.TypeMapping(type, type); _registry = new CommandRegistry(commandHandlerExecuter, options.CommandHandlerContainerRegistration ?? resolverContainerRegistration); } dependencyResolver.RegisterInstance(_registry); } // the enricher is always shared, but vagaries of different IoC containers mean its dangerous to rely // on dependecy resolver checks for an existing registration lock (_enrichmentLockObject) { if (_dispatchContextEnrichment == null || options.Reset) { _dispatchContextEnrichment = new CommandDispatchContextEnrichment(options.Enrichers ?? new List <ICommandDispatchContextEnricher>()); } else if (options.Enrichers != null) { _dispatchContextEnrichment.AddEnrichers(options.Enrichers); } dependencyResolver.RegisterInstance(_dispatchContextEnrichment); } lock (_auditItemEnricherPipelineLockObject) { if (_auditItemEnricherPipeline == null || options.Reset) { _auditItemEnricherPipeline = new AuditItemEnricherPipeline( options.AuditItemEnricherFactoryFunc ?? (type => (IAuditItemEnricher)dependencyResolver.Resolve(type))); } dependencyResolver.RegisterInstance(_auditItemEnricherPipeline); } lock (_auditorPipelineLockObject) { if (_auditorPipeline == null || options.Reset) { _auditorPipeline = new CommandAuditPipeline(t => (ICommandAuditor)dependencyResolver.Resolve(t), dependencyResolver.Resolve <ICommandAuditSerializer>, _auditItemEnricherPipeline); } dependencyResolver.RegisterInstance(_auditorPipeline); } ICommandHandlerFactory commandHandlerFactory = new CommandHandlerFactory(options.CommandHandlerFactoryFunc ?? dependencyResolver.Resolve); IPipelineAwareCommandHandlerExecuter pipelineAwareCommandHandlerExecuter = new PipelineAwareCommandHandlerExecuter(); dependencyResolver.RegisterInstance(commandHandlerFactory); dependencyResolver.RegisterInstance(pipelineAwareCommandHandlerExecuter); dependencyResolver.TypeMapping <ICommandAuditorFactory, NullCommandAuditorFactory>(); dependencyResolver.TypeMapping <ICommandScopeManager, AsyncLocalCommandScopeManager>(); dependencyResolver.TypeMapping <IFrameworkCommandDispatcher, CommandDispatcher>(); dependencyResolver.TypeMapping <ICommandDispatcher, CommandDispatcher>(); dependencyResolver.TypeMapping <IFrameworkCommandExecuter, CommandExecuter>(); dependencyResolver.TypeMapping <ICommandExecuter, CommandExecuter>(); dependencyResolver.TypeMapping <IDirectCommandExecuter, DirectCommandExecuter>(); if (options.DisableCorrelationIds) { dependencyResolver.TypeMapping <ICommandCorrelationIdProvider, DisabledCorrelationIdProvider>(); } else { if (options.UseLocallyUniqueCorrelationIds) { dependencyResolver .TypeMapping <ICommandCorrelationIdProvider, LocallyUniqueCommandCorrelationIdProvider>(); } else { dependencyResolver.TypeMapping <ICommandCorrelationIdProvider, CommandCorrelationIdProvider>(); } } dependencyResolver.TypeMapping <ICommandAuditSerializer, CommandAuditSerializer>(); dependencyResolver.TypeMapping(typeof(ICommandExecutionExceptionHandler), options.CommandExecutionExceptionHandler ?? typeof(DefaultCommandExecutionExceptionHandler)); return(_registry); }