CommandProcessor GetCommandProcessor(bool useCaching) { var eventStore = new MongoDbEventStore(_database, "events"); _timeTaker = new TimeTaker { InnerEventStore = eventStore, }; var serializer = new JsonDomainEventSerializer(); IAggregateRootRepository aggregateRootRepository = new DefaultAggregateRootRepository(_timeTaker, serializer, _domainTypeNameMapper); if (useCaching) { aggregateRootRepository = new CachingAggregateRootRepositoryDecorator(aggregateRootRepository, new InMemorySnapshotCache { ApproximateMaxNumberOfCacheEntries = 100 }, eventStore, serializer); } _timeTaker.InnerAggregateRootRepository = aggregateRootRepository; var eventDispatcher = new ViewManagerEventDispatcher(_timeTaker, eventStore, serializer, _domainTypeNameMapper); var commandProcessor = new CommandProcessor(_timeTaker, _timeTaker, eventDispatcher, serializer, _commandMapper, _domainTypeNameMapper, new Options()); RegisterForDisposal(commandProcessor); return commandProcessor; }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(minLevel: Logger.Level.Debug); _mongoDatabase = MongoHelper.InitializeTestDatabase(); _commandProcessor = CommandProcessor.With() .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn)) .EventStore(e => e.UseMongoDb(_mongoDatabase, "Events")) .EventDispatcher(e => e.Register <IEventDispatcher>(r => { var repository = r.Get <IAggregateRootRepository>(); var serializer = r.Get <IDomainEventSerializer>(); var typeMapper = r.Get <IDomainTypeNameMapper>(); _thisBadBoyEnsuresThatTheEventStoreIsNotUsed = new ThrowingEventStore(); _dispatcher = new ViewManagerEventDispatcher(repository, _thisBadBoyEnsuresThatTheEventStoreIsNotUsed, serializer, typeMapper) { AutomaticCatchUpInterval = TimeSpan.FromHours(24) //<effectively disable automatic catchup }; return(_dispatcher); })) .Create(); RegisterForDisposal(_commandProcessor); }
protected override void DoSetUp() { var servicePath = TestAzureHelper.GetPath("test"); _commandProcessor = CommandProcessor.With() .Logging(l => l.UseConsole(minLevel: Logger.Level.Debug)) .EventStore(e => e.Register <IEventStore>(c => new InMemoryEventStore())) .EventDispatcher(e => e.UseAzureServiceBusRelayEventDispatcher("cirqus", servicePath, TestAzureHelper.KeyName, TestAzureHelper.SharedAccessKey)) .Create(); RegisterForDisposal(_commandProcessor); _eventStoreProxy = new AzureServiceBusRelayEventStoreProxy("cirqus", servicePath, TestAzureHelper.KeyName, TestAzureHelper.SharedAccessKey); RegisterForDisposal(_eventStoreProxy); _viewManager = new InMemoryViewManager <View>(); var serializer = new JsonDomainEventSerializer(); var typeMapper = new DefaultDomainTypeNameMapper(); var eventDispatcher = new ViewManagerEventDispatcher(new DefaultAggregateRootRepository(_eventStoreProxy, serializer, typeMapper), _eventStoreProxy, serializer, typeMapper); RegisterForDisposal(eventDispatcher); eventDispatcher.AddViewManager(_viewManager); eventDispatcher.Initialize(); }
/// <summary> /// Registers a <see cref="Views.ViewManagerEventDispatcher"/> to manage the given views. Can be called multiple times in order to register /// multiple "pools" of views (each will be managed by a dedicated worker thread). /// </summary> public ViewManagerEventDispatcherConfiguationBuilder UseViewManagerEventDispatcher(params IViewManager[] viewManagers) { var viewManagerConfigurationContainer = new ConfigurationContainer(); UseEventDispatcher(context => { var viewManagerContext = viewManagerConfigurationContainer.CreateContext(); context.AddChildContext(viewManagerContext); var eventDispatcher = new ViewManagerEventDispatcher( context.Get <IAggregateRootRepository>(), context.Get <IEventStore>(), context.Get <IDomainEventSerializer>(), context.Get <IDomainTypeNameMapper>(), viewManagers); var waitHandle = viewManagerContext.GetOrDefault <ViewManagerWaitHandle>(); if (waitHandle != null) { waitHandle.Register(eventDispatcher); } var maxDomainEventsPerBatch = viewManagerContext.GetOrDefault <int>(); if (maxDomainEventsPerBatch > 0) { eventDispatcher.MaxDomainEventsPerBatch = maxDomainEventsPerBatch; } var viewManagerProfiler = viewManagerContext.GetOrDefault <IViewManagerProfiler>(); if (viewManagerProfiler != null) { eventDispatcher.SetProfiler(viewManagerProfiler); } var contextItems = viewManagerContext.GetOrDefault <IDictionary <string, object> >(); if (contextItems != null) { eventDispatcher.SetContextItems(contextItems); } var autoDistributionViewManagerEventDispatcher = viewManagerContext.GetOrDefault <AutoDistributionViewManagerEventDispatcher>(); if (autoDistributionViewManagerEventDispatcher != null) { autoDistributionViewManagerEventDispatcher.Register(eventDispatcher); return(autoDistributionViewManagerEventDispatcher); } return(eventDispatcher); }); return(new ViewManagerEventDispatcherConfiguationBuilder(viewManagerConfigurationContainer)); }
/// <summary> /// Registers a <see cref="Views.ViewManagerEventDispatcher"/> to manage the given views. Can be called multiple times in order to register /// multiple "pools" of views (each will be managed by a dedicated worker thread). /// </summary> public ViewManagerEventDispatcherConfigurationBuilder UseViewManagerEventDispatcher(params IViewManager[] viewManagers) { var viewManagerConfigurationContainer = new NewConfigurationContainer(_services); UseEventDispatcher(context => { var scope = context.CreateScope(); var eventDispatcher = new ViewManagerEventDispatcher( scope.ServiceProvider.GetService <IAggregateRootRepository>(), scope.ServiceProvider.GetService <IEventStore>(), scope.ServiceProvider.GetService <IDomainEventSerializer>(), scope.ServiceProvider.GetService <IDomainTypeNameMapper>(), viewManagers); var waitHandle = scope.ServiceProvider.GetService <ViewManagerWaitHandle>(); if (waitHandle != null) { waitHandle.Register(eventDispatcher); } var configuration = scope.ServiceProvider.GetService <ViewManagerEventDispatcherConfiguration>(); if (configuration?.MaxDomainEventsPerBatch > 0) { eventDispatcher.MaxDomainEventsPerBatch = configuration.MaxDomainEventsPerBatch; } var viewManagerProfiler = scope.ServiceProvider.GetService <IViewManagerProfiler>(); if (viewManagerProfiler != null) { eventDispatcher.SetProfiler(viewManagerProfiler); } var contextItems = scope.ServiceProvider.GetService <IDictionary <string, object> >(); if (contextItems != null) { eventDispatcher.SetContextItems(contextItems); } var autoDistributionViewManagerEventDispatcher = scope.ServiceProvider.GetService <AutoDistributionViewManagerEventDispatcher>(); if (autoDistributionViewManagerEventDispatcher != null) { autoDistributionViewManagerEventDispatcher.Register(eventDispatcher); return(autoDistributionViewManagerEventDispatcher); } return(eventDispatcher); }); return(new ViewManagerEventDispatcherConfigurationBuilder(viewManagerConfigurationContainer)); }
internal TestContext(InMemoryEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _testCommandMapper = commandMapper; _domainTypeNameMapper = domainTypeNameMapper; _viewManagerEventDispatcher = eventDispatcher as ViewManagerEventDispatcher; if (_viewManagerEventDispatcher != null) { _waitHandle.Register(_viewManagerEventDispatcher); } }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(minLevel: Logger.Level.Debug); _mongoDatabase = MongoHelper.InitializeTestDatabase(); //Brett _commandProcessor = CreateCommandProcessor(config => config .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn)) .EventStore(e => e.UseMongoDb(_mongoDatabase, "Events")) .EventDispatcher(e => e.Register <IEventDispatcher>(r => { var repository = (IAggregateRootRepository)r.GetService(typeof(IAggregateRootRepository)); var eventStore = (IEventStore)r.GetService(typeof(IEventStore)); var serializer = (IDomainEventSerializer)r.GetService(typeof(IDomainEventSerializer)); var typeMapper = (IDomainTypeNameMapper)r.GetService(typeof(IDomainTypeNameMapper)); _dispatcher = new ViewManagerEventDispatcher(repository, eventStore, serializer, typeMapper); return(_dispatcher); })) ); //Orig //_commandProcessor = CommandProcessor.With() // .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn)) // .EventStore(e => e.UseMongoDb(_mongoDatabase, "Events")) // .EventDispatcher(e => e.Register<IEventDispatcher>(r => // { // var repository = r.Get<IAggregateRootRepository>(); // var eventStore = r.Get<IEventStore>(); // var serializer = r.Get<IDomainEventSerializer>(); // var typeMapper = r.Get<IDomainTypeNameMapper>(); // _dispatcher = new ViewManagerEventDispatcher(repository, eventStore, serializer, typeMapper); // return _dispatcher; // })) // .Create(); RegisterForDisposal(_commandProcessor); }
protected override void DoSetUp() { _viewManager1 = new InMemoryViewManager <MyViewInstance>(); _viewManager2 = new InMemoryViewManager <MyViewInstanceImplicit>(); _viewManager3 = new InMemoryViewManager <MyViewInstanceEmitting>(); _viewManager4 = new InMemoryViewManager <MyViewInstanceLoadingNonexistentRoot>(); _cirqus = CreateCommandProcessor(config => config .EventStore(e => e.UseInMemoryEventStore()) .EventDispatcher(e => e.Register <IEventDispatcher>(c => { var repository = c.GetService <IAggregateRootRepository>(); var store = c.GetService <IEventStore>(); var serializer = c.GetService <IDomainEventSerializer>(); var typeMapper = c.GetService <IDomainTypeNameMapper>(); _eventDispatcher = new ViewManagerEventDispatcher(repository, store, serializer, typeMapper); return(_eventDispatcher); }))); RegisterForDisposal(_cirqus); }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(minLevel: Logger.Level.Debug); _mongoDatabase = MongoHelper.InitializeTestDatabase(); _commandProcessor = CommandProcessor.With() .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn)) .EventStore(e => e.UseMongoDb(_mongoDatabase, "Events")) .EventDispatcher(e => e.Register<IEventDispatcher>(r => { var repository = r.Get<IAggregateRootRepository>(); var eventStore = r.Get<IEventStore>(); var serializer = r.Get<IDomainEventSerializer>(); var typeMapper = r.Get<IDomainTypeNameMapper>(); _dispatcher = new ViewManagerEventDispatcher(repository, eventStore, serializer, typeMapper); return _dispatcher; })) .Create(); RegisterForDisposal(_commandProcessor); }
internal void Register(ViewManagerEventDispatcher dispatcher) { _dispatchers.Add(dispatcher); }
/// <summary> /// Registers the given view manager event dispatcher /// </summary> public void Register(ViewManagerEventDispatcher eventDispatcher) { if (_eventDispatcher != null) { throw new InvalidOperationException(string.Format("Cannot register {0} because {1} was already registered!", eventDispatcher, _eventDispatcher)); } _eventDispatcher = eventDispatcher; _viewManagers.AddRange(_eventDispatcher.GetViewManagers()); }