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>()); }
public ICommandRegistry AddCommanding(ICommandingDependencyResolverAdapter dependencyResolver) { var registry = dependencyResolver.AddCommanding(); var auditRootOnly = false; dependencyResolver .AddPreDispatchCommandingAuditor <ConsoleAuditor>(auditRootOnly) .AddPostDispatchCommandingAuditor <ConsoleAuditor>(auditRootOnly) .AddExecutionCommandingAuditor <ConsoleAuditor>(auditRootOnly); return(registry); }
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>()); }
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>()); }