Exemple #1
0
        private static ICommandDispatcher Configure()
        {
            IServiceCollection            serviceCollection  = new ServiceCollection();
            ICommandingDependencyResolver 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.UseCommanding(options)
            .Register <ChainCommandHandler>()
            .Register <OutputWorldToConsoleCommandHandler>();
            dependencyResolver.UseEventHubCommandAuditing(EventHubConnectionString, EventHubName);
            _serviceProvider = serviceCollection.BuildServiceProvider();
            return(_serviceProvider.GetService <ICommandDispatcher>());
        }