private static void EnsureRuntimeIsAssociated(ICommandingDependencyResolverAdapter resolver)
 {
     if (resolver.AssociatedCommandingRuntime == null)
     {
         throw new CommandFrameworkConfigurationException("The core commanding framework must be registered first.");
     }
 }
 private static void EnsureCommandingRuntime(ICommandingDependencyResolverAdapter dependencyResolver)
 {
     if (dependencyResolver.AssociatedCommandingRuntime == null)
     {
         throw new CommandFrameworkConfigurationException("The commanding package should be configured first");
     }
 }
        public static ICommandingDependencyResolverAdapter AddCommandRedisCache(this ICommandingDependencyResolverAdapter resolver, string connectionString)
        {
            ICacheAdapter adapter = new RedisCacheAdapter(new Lazy <ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(connectionString)));

            resolver.RegisterInstance(adapter);
            return(resolver);
        }
        private static async Task <ICommandDispatcher> ConfigureEnqueue()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            CloudQueue          auditQueue     = storageAccount.CreateCloudQueueClient().GetQueueReference("auditqueue");
            await auditQueue.CreateIfNotExistsAsync();

            IServiceCollection serviceCollection = new ServiceCollection();
            ICommandingDependencyResolverAdapter dependencyResolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider);

            IReadOnlyDictionary <string, object> Enricher(IReadOnlyDictionary <string, object> existing) => new Dictionary <string, object>
            {
                { "ExampleEnrichedCounter", Interlocked.Increment(ref _counter) }
            };
            Options options = new Options
            {
                Reset     = true, // we reset the registry because we allow repeat runs, in a normal app this isn't required
                Enrichers = new[] { new FunctionWrapperCommandDispatchContextEnricher(Enricher) }
            };

            dependencyResolver.AddCommanding(options)
            .Register <ChainCommandHandler>()
            .Register <OutputWorldToConsoleCommandHandler>();
            dependencyResolver.AddAzureStorageCommandAuditing(auditQueue);
            _serviceProvider = serviceCollection.BuildServiceProvider();
            return(_serviceProvider.GetService <ICommandDispatcher>());
        }
 private static ICommandingDependencyResolverAdapter Register <TSerializer>(this ICommandingDependencyResolverAdapter dependencyResolver) where TSerializer : IAzureStorageQueueSerializer
 {
     dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, TSerializer>();
     dependencyResolver.TypeMapping <IAzureStorageCommandQueueProcessorFactory, AzureStorageCommandQueueProcessorFactory>();
     dependencyResolver.TypeMapping <IAzureStorageQueueDispatcherFactory, AzureStorageQueueDispatcherFactory>();
     return(dependencyResolver);
 }
        public static ICommandingDependencyResolverAdapter AddCommandRedisCache(this ICommandingDependencyResolverAdapter resolver, Lazy <ConnectionMultiplexer> multiplexer)
        {
            ICacheAdapter adapter = new RedisCacheAdapter(multiplexer);

            resolver.RegisterInstance(adapter);
            return(resolver);
        }
Пример #7
0
 /// <summary>
 /// Registers the commanding system in an ioc container.
 /// If the container is not able to resolve unregistered types (for example the NetStandard Microsoft container) then
 /// the commandHandlerContainerRegistration should be used to perform the type registration for the handler
 /// </summary>
 /// <param name="dependencyResolver">The dependency resolver to register inside</param>
 /// <param name="commandHandlerContainerRegistration">
 /// Unless an alternative implementation of ICommandHandlerFactory is supplied then actors are created through the dependency resolver
 /// but not all IoC containers can resolve unregistered concrete types (for example the built in ASP.Net Core IServiceCollection
 /// and IServiceProvider IoC cannot). Where this is the case supply an implementation for the CommandHandlerContainerRegistration
 /// action that registers the actors in the container. For example using an IServiceCollection instance of serviceCollection:
 ///     resolver.UseCommanding(type => services.AddTransient(type, type));
 /// </param>
 /// <returns>The dependency resolver</returns>
 public ICommandRegistry AddCommanding(ICommandingDependencyResolverAdapter dependencyResolver,
                                       Action <Type> commandHandlerContainerRegistration)
 {
     return(AddCommanding(dependencyResolver,
                          new Options {
         CommandHandlerContainerRegistration = commandHandlerContainerRegistration
     }));
 }
 private static ICommandingDependencyResolverAdapter Register <TSerializer>(ICommandingDependencyResolverAdapter 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, HttpCommandDispatcherFactoryImpl>();
     return(dependencyResolver);
 }
        public ICommandRegistry AddCommanding(ICommandingDependencyResolverAdapter dependencyResolver)
        {
            var registry      = dependencyResolver.AddCommanding();
            var auditRootOnly = false;

            dependencyResolver
            .AddPreDispatchCommandingAuditor <ConsoleAuditor>(auditRootOnly)
            .AddPostDispatchCommandingAuditor <ConsoleAuditor>(auditRootOnly)
            .AddExecutionCommandingAuditor <ConsoleAuditor>(auditRootOnly);
            return(registry);
        }
        public static ICommandingDependencyResolverAdapter AddQueues(this ICommandingDependencyResolverAdapter 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);
        }
Пример #11
0
 /// <summary>
 /// Registers an auditor that will be invoked directly after a command has been executed.
 /// </summary>
 /// <typeparam name="TExecutionAuditorImpl">The type of the auditor</typeparam>
 /// <param name="dependencyResolver">The dependency resolver</param>
 /// <param name="auditRootCommandOnly">By default the built in auditor will audit every command that is dispatched however if using the audit as part of an
 /// event sourcing pipeline it can be useful to only audit the root command and exclude any commands dispatched as a result
 /// of that root command. Set this property to true to audit only the root commands, leave null or set to false to audit all
 /// commands.</param>
 /// <returns>The dependency resolver</returns>
 public ICommandingDependencyResolverAdapter AddExecutionCommandingAuditor <TExecutionAuditorImpl>(
     ICommandingDependencyResolverAdapter 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);
 }
Пример #12
0
        private static ICommandDispatcher Configure()
        {
            IServiceCollection serviceCollection = new ServiceCollection();
            ICommandingDependencyResolverAdapter dependencyResolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider);

            IReadOnlyDictionary <string, object> Enricher(IReadOnlyDictionary <string, object> existing) => new Dictionary <string, object>
            {
                { "ExampleEnrichedCounter", Interlocked.Increment(ref _counter) }
            };
            Options options = new Options
            {
                Reset     = true, // we reset the registry because we allow repeat runs, in a normal app this isn't required
                Enrichers = new[] { new FunctionWrapperCommandDispatchContextEnricher(Enricher) }
            };

            dependencyResolver.AddCommanding(options)
            .Register <SimpleCommand>(AzureEventHubDispatcherFactory.CreateCommandDispatcherFactory(EventHubConnectionString, EventHubName));
            _serviceProvider = serviceCollection.BuildServiceProvider();
            return(_serviceProvider.GetService <ICommandDispatcher>());
        }
Пример #13
0
        /// <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 ICommandingDependencyResolverAdapter AddCommandCache(
            this ICommandingDependencyResolverAdapter 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);
        }
        private static async Task <IAzureStorageAuditQueueProcessorFactory> ConfigureDequeue(IStorageStrategy storageStrategy)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            CloudQueue          auditQueue     = storageAccount.CreateCloudQueueClient().GetQueueReference("auditqueue");
            await auditQueue.CreateIfNotExistsAsync();

            IServiceCollection serviceCollection          = new ServiceCollection();
            ICommandingDependencyResolverAdapter resolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider);
            Options options = new Options
            {
                Reset = true // we reset the registry because we allow repeat runs, in a normal app this isn't required
            };

            resolver.AddCommanding(options);
            resolver.AddQueues();
            resolver.AddAzureStorageCommandAuditing(storageAccount, storageStrategy: storageStrategy); // this sets up the table store auditors
            resolver.AddAzureStorageAuditQueueProcessor(auditQueue);                                   // this sets up queue listening
            _serviceProvider = serviceCollection.BuildServiceProvider();

            return(_serviceProvider.GetService <IAzureStorageAuditQueueProcessorFactory>());
        }
Пример #15
0
        public static ICommandingDependencyResolverAdapter AddCommandMemoryCache(this ICommandingDependencyResolverAdapter resolver)
        {
            resolver.TypeMapping <ICacheAdapter, MemoryCacheAdapter>();

            return(resolver);
        }
 public static ICommandingDependencyResolverAdapter AddAzureServiceBus(this ICommandingDependencyResolverAdapter dependencyResolver)
 {
     dependencyResolver.TypeMapping <IServiceBusMessageSerializer, JsonServiceBusMessageSerializer>();
     dependencyResolver.TypeMapping <IServiceBusCommandQueueProcessorFactory, ServiceBusCommandQueueProcessorFactory>();
     return(dependencyResolver);
 }
        /// <summary>
        /// Sets up azure storage command auditing for direct output to tables
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver</param>
        /// <param name="cloudStorageAccount">The cloud storage account to use for storage</param>
        /// <param name="commandPayloadContainer">(Optional) The blob container that </param>
        /// <param name="storageStrategy"></param>
        /// <param name="options">Auditor options</param>
        /// <returns></returns>
        public static ICommandingDependencyResolverAdapter AddAzureStorageCommandAuditing(this ICommandingDependencyResolverAdapter dependencyResolver,
                                                                                          CloudStorageAccount cloudStorageAccount,
                                                                                          CloudBlobContainer commandPayloadContainer = null,
                                                                                          IStorageStrategy storageStrategy           = null,
                                                                                          AzureStorageAuditorOptions options         = null)
        {
            options = options ?? new AzureStorageAuditorOptions();

            if (!options.UseExecutionAuditor && !options.UsePostDispatchAuditor && !options.UsePreDispatchAuditor)
            {
                throw new AzureStorageConfigurationException("At least one auditor type must be configured");
            }
            CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

            if (commandPayloadContainer == null)
            {
                commandPayloadContainer = cloudStorageAccount.CreateCloudBlobClient().GetContainerReference("commandauditpayload");
            }
            if (storageStrategy == null)
            {
                storageStrategy = new SingleTableStrategy();
            }

            ICloudStorageProvider cloudStorageProvider = new CloudStorageProvider(cloudTableClient, commandPayloadContainer);

            dependencyResolver.RegisterInstance(cloudStorageProvider);
            dependencyResolver.RegisterInstance(storageStrategy);
            if (options.UsePreDispatchAuditor)
            {
                EnsureCommandingRuntime(dependencyResolver);
                dependencyResolver.AssociatedCommandingRuntime.AddPreDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                EnsureCommandingRuntime(dependencyResolver);
                dependencyResolver.AssociatedCommandingRuntime.AddPostDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                EnsureCommandingRuntime(dependencyResolver);
                dependencyResolver.AssociatedCommandingRuntime.AddExecutionCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditExecuteDispatchRootOnly);
            }

            return(dependencyResolver);
        }
Пример #18
0
 /// <summary>
 /// Adds an audit item enricher
 /// </summary>
 /// <typeparam name="TAuditItemEnricher">The type of the enricher</typeparam>
 /// <param name="commandingDependencyResolver">The commanding dependency resolver</param>
 /// <returns>The commanding dependency resolver</returns>
 public ICommandingDependencyResolverAdapter AddAuditItemEnricher <TAuditItemEnricher>(ICommandingDependencyResolverAdapter 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);
 }
Пример #19
0
        /// <summary>
        /// Registers the commanding system in an ioc container.
        /// If the container is not able to resolve unregistered types (for example the NetStandard Microsoft container) then
        /// the commandHandlerContainerRegistration should be used to perform the type registration for the handler
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver to register inside</param>
        /// <param name="options">Configuration options for the commanding system</param>
        /// <returns>The dependency resolver</returns>
        public ICommandRegistry AddCommanding(ICommandingDependencyResolverAdapter 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);
        }
 public static ICommandingDependencyResolverAdapter AddAzureStorageCommanding(this ICommandingDependencyResolverAdapter dependencyResolver)
 {
     Register <JsonSerializer>(dependencyResolver);
     return(dependencyResolver);
 }
 public static ICommandingDependencyResolverAdapter AddHttpCommanding <TSerializer>(this ICommandingDependencyResolverAdapter dependencyResolver, HttpClient client = null) where TSerializer : IHttpCommandSerializer
 {
     Register <TSerializer>(dependencyResolver, client);
     return(dependencyResolver);
 }
 public static ICommandingDependencyResolverAdapter AddHttpCommanding(this ICommandingDependencyResolverAdapter dependencyResolver, HttpClient client = null)
 {
     Register <JsonCommandSerializer>(dependencyResolver, client);
     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 ICommandingDependencyResolverAdapter AddEventHubCommandAuditing(this ICommandingDependencyResolverAdapter 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)
            {
                EnsureRuntimeIsAssociated(resolver);
                resolver.AssociatedCommandingRuntime.AddPreDispatchCommandingAuditor <AzureEventHubCommandAuditor>(resolver, options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                EnsureRuntimeIsAssociated(resolver);
                resolver.AssociatedCommandingRuntime.AddPostDispatchCommandingAuditor <AzureEventHubCommandAuditor>(resolver, options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                EnsureRuntimeIsAssociated(resolver);
                resolver.AssociatedCommandingRuntime.AddExecutionCommandingAuditor <AzureEventHubCommandAuditor>(resolver, options.AuditExecuteDispatchRootOnly);
            }
            return(resolver);
        }
        public static ICommandingDependencyResolverAdapter AddMicrosoftLoggingExtensionsAuditor(this ICommandingDependencyResolverAdapter resolver,
                                                                                                LogLevel normalLogLevel           = LogLevel.Trace,
                                                                                                LogLevel executionFailureLogLevel = LogLevel.Warning,
                                                                                                MicrosoftLoggingExtensionsAuditorOptions options = null)
        {
            options = options ?? new MicrosoftLoggingExtensionsAuditorOptions();
            ILogLevelProvider logLevelProvider = new LogLevelProvider(normalLogLevel, executionFailureLogLevel);

            resolver.RegisterInstance(logLevelProvider);

            if (options.UsePreDispatchAuditor)
            {
                EnsureCommandingRuntime(resolver);
                resolver.AssociatedCommandingRuntime.AddPreDispatchCommandingAuditor <LoggerCommandAuditor>(resolver, options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                EnsureCommandingRuntime(resolver);
                resolver.AssociatedCommandingRuntime.AddPostDispatchCommandingAuditor <LoggerCommandAuditor>(resolver, options.AuditPostDispatchRootOnly);
            }
            if (options.UsePreDispatchAuditor)
            {
                EnsureCommandingRuntime(resolver);
                resolver.AssociatedCommandingRuntime.AddExecutionCommandingAuditor <LoggerCommandAuditor>(resolver, options.AuditExecuteDispatchRootOnly);
            }

            return(resolver);
        }
        /// <summary>
        /// Sets up azure storage command auditing for output to a queue. This is best suited for scenarios
        /// where there are multiple auditors or storage mechanisms in the audit pipeline as it enables
        /// execution of the command dispatch pipeline to rapidly continue but still with a guarantee
        /// that the command will be audited.
        ///
        /// Generally when configuring this auditor no other auditors are configured - but you can.
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver</param>
        /// <param name="queue">The queue to audit via</param>
        /// <param name="blobContainer">The blob container to store the payload to. If this is set then the
        /// payload is stored before the item is queued, if left null then the payload will be serialized
        /// into the queue item. The default setting of null is the more performant and common case, setting
        /// the container here is only useful for very large command payloads that won't fit inside a queue
        /// item. If the payload is stored in the blob container specified here then there will be no way
        /// for downstream auditors to access it from the AuditItem model - it will be null.
        /// </param>
        /// <param name="storageStrategy"></param>
        /// <returns></returns>
        public static ICommandingDependencyResolverAdapter AddAzureStorageCommandAuditing(this ICommandingDependencyResolverAdapter 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.AddPreDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                EnsureCommandingRuntime(dependencyResolver);
                dependencyResolver.AssociatedCommandingRuntime.AddPostDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                EnsureCommandingRuntime(dependencyResolver);
                dependencyResolver.AssociatedCommandingRuntime.AddExecutionCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditExecuteDispatchRootOnly);
            }
            return(dependencyResolver);
        }
 public static ICommandingDependencyResolverAdapter AddAzureStorageCommanding <TSerializer>(this ICommandingDependencyResolverAdapter dependencyResolver) where TSerializer : IAzureStorageQueueSerializer
 {
     Register <TSerializer>(dependencyResolver);
     return(dependencyResolver);
 }
Пример #27
0
 /// <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="options">Cache options</param>
 /// <returns>The dependency resolver</returns>
 public static ICommandingDependencyResolverAdapter AddCommandCache(this ICommandingDependencyResolverAdapter resolver, ICacheKeyProvider cacheKeyProvider, params CacheOptions[] options)
 {
     return(AddCommandCache(resolver, cacheKeyProvider, false, options));
 }
        /// <summary>
        /// Registers the IAzureStorageCommandQueueProcessorFactory interface through which a audit queue processor task can be
        /// started
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver</param>
        /// <param name="queue">The queue to dequeue from</param>
        /// <param name="deadLetterQueue">An optional dead letter queue to place items in if errors repeatedly occur in item processing</param>
        /// <returns>The dependency resovler</returns>
        public static ICommandingDependencyResolverAdapter AddAzureStorageAuditQueueProcessor(this ICommandingDependencyResolverAdapter 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);
        }
Пример #29
0
 /// <summary>
 /// Sets up the cache with the default cache key provider that uses the command type, property names and property values to
 /// generate a hashable string
 /// </summary>
 /// <param name="resolver">The dependency resolver</param>
 /// <param name="options">Cache options</param>
 /// <param name="replaceDefaultCommandDispatcher">If true then the default ICommandDispatcher will be replaced with the caching variant</param>
 /// <returns>The dependency resolver</returns>
 public static ICommandingDependencyResolverAdapter AddCommandCache(this ICommandingDependencyResolverAdapter resolver, bool replaceDefaultCommandDispatcher, params CacheOptions[] options)
 {
     return(AddCommandCache(resolver, new PropertyCacheKeyProvider(new PropertyCacheKeyProviderCompiler(), new SimpleCacheKeyHash()), replaceDefaultCommandDispatcher, options));
 }
        /// <summary>
        /// Registers a command auditor that writes to an event hub
        /// </summary>
        /// <param name="resolver">Dependency resolver</param>
        /// <param name="connectionString">Connection string to an event hub e.g.:
        /// Endpoint=sb://myeventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=mysharedaccesskey
        /// </param>
        /// <param name="entityPath">The path to the event hub (usually just the event hub name</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 ICommandingDependencyResolverAdapter AddEventHubCommandAuditing(this ICommandingDependencyResolverAdapter resolver,
                                                                                      string connectionString,
                                                                                      string entityPath,
                                                                                      IPartitionKeyProvider partitionKeyProvider = null,
                                                                                      AzureEventHubAuditorOptions options        = null)
        {
            EventHubsConnectionStringBuilder builder =
                new EventHubsConnectionStringBuilder(connectionString)
            {
                EntityPath = entityPath
            };

            Microsoft.Azure.EventHubs.EventHubClient client = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(builder.ToString());
            return(AddEventHubCommandAuditing(resolver, client, partitionKeyProvider, options));
        }