public SynchronousDispatcherWireup(Wireup wireup, IPublishMessages publisher)
     : base(wireup)
 {
     this.PublishTo(publisher ?? new NullDispatcher());
     this.Container.Register<IDispatchCommits>(c => new SynchronousDispatcher(
         c.Resolve<IPublishMessages>(), c.Resolve<IPersistStreams>()));
 }
 public MongoPersistenceWireup(Wireup inner, string connectionName, IDocumentSerializer serializer)
     : base(inner)
 {
     this.Container.Register(c => new MongoPersistenceFactory(
         connectionName,
         serializer).Build());
 }
Exemple #3
0
        public NESWireup(Wireup wireup)
            : base(wireup)
        {
            var serializer = Container.Resolve<ISerialize>();

            if (serializer != null)
            {
                Logger.Debug("Configuring custom NES serializer to cope with payloads that contain messages as interfaces.");
                Logger.Debug("Wrapping serializer of type '{0}' in '{1}'", serializer.GetType(), typeof(CompositeSerializer));

                this.Container.Register<ISerialize>(new CompositeSerializer(serializer, () => DI.Current.Resolve<IEventSerializer>()));
            }

            Logger.Debug("Configuring the store to dispatch messages synchronously.");
            Logger.Debug("Registering dispatcher of type '{0}'.", typeof(MessageDispatcher));

            this.Container.Register<IDispatchCommits>(new MessageDispatcher(() => DI.Current.Resolve<IEventPublisher>()));
            this.Container.Register<IScheduleDispatches>(c =>
            {
                var dispatchScheduler = new SynchronousDispatchScheduler(
                    c.Resolve<IDispatchCommits>(),
                    c.Resolve<IPersistStreams>());
                if (c.Resolve<DispatcherSchedulerStartup>() == DispatcherSchedulerStartup.Auto)
                {
                    dispatchScheduler.Start();
                }

                return dispatchScheduler;
            });

            DI.Current.Register<IEventStore, IStoreEvents>(eventStore => new EventStoreAdapter(eventStore));
        }
 public SynchronousDispatchSchedulerWireup(Wireup wireup, IDispatchCommits dispatcher)
     : base(wireup)
 {
     Logger.Debug(Messages.SyncDispatchSchedulerRegistered);
     this.DispatchTo(dispatcher ?? new NullDispatcher());
     this.Container.Register<IScheduleDispatches>(c => new SynchronousDispatchScheduler(
         c.Resolve<IDispatchCommits>(), c.Resolve<IPersistStreams>()));
 }
Exemple #5
0
        public NESWireup(Wireup inner)
            : base(inner)
        {
            Container.Register<ISerialize>(new Serializer(Container.Resolve<ISerialize>(), () => DI.Current.Resolve<IEventSerializer>()));
            Container.Register<IPublishMessages>(new MessagePublisher(() => DI.Current.Resolve<IEventPublisher>()));
            Container.Register<IDispatchCommits>(c => new AsynchronousDispatcher(c.Resolve<IPublishMessages>(), c.Resolve<IPersistStreams>()));

            DI.Current.Register<IEventStore, IStoreEvents>(eventStore => new EventStoreAdapter(eventStore));
            DI.Current.Register(() => Container.Resolve<IStoreEvents>());
        }
        public SqlPersistenceWireup(Wireup wireup, IConnectionFactory connectionFactory)
            : base(wireup)
        {
            this.Container.Register<ISqlDialect>(c => null); // auto-detect

            this.Container.Register(c => new SqlPersistenceFactory(
                connectionFactory,
                c.Resolve<ISerialize>(),
                c.Resolve<ISqlDialect>(),
                c.Resolve<TransactionScopeOption>()).Build());
        }
        public AsynchronousDispatchSchedulerWireup(Wireup wireup, IDispatchCommits dispatcher)
            : base(wireup)
        {
            var option = this.Container.Resolve<TransactionScopeOption>();
            if (option == TransactionScopeOption.Required)
                Logger.Warn(Messages.SynchronousDispatcherTwoPhaseCommits);

            Logger.Debug(Messages.AsyncDispatchSchedulerRegistered);
            this.DispatchTo(dispatcher ?? new NullDispatcher());
            this.Container.Register<IScheduleDispatches>(c => new AsynchronousDispatchScheduler(
                c.Resolve<IDispatchCommits>(), c.Resolve<IPersistStreams>()));
        }
        public MongoPersistenceWireup(Wireup inner, string connectionName, IDocumentSerializer serializer) : base(inner)
        {
            Logger.Debug("Configuring Mongo persistence engine.");

            var options = Container.Resolve<TransactionScopeOption>();
            if (options != TransactionScopeOption.Suppress)
            {
                Logger.Warn("MongoDB does not participate in transactions using TransactionScope.");
            }

            Container.Register(c => new MongoPersistenceFactory(connectionName, serializer).Build());
        }
 static void Build(IIocContainer container, string connectionString)
 {
     container.RegisterInstance <IStoreEvents>(() =>
                                               Wireup.Init()
                                               .UsingSqlPersistence(connectionString)
                                               .WithDialect(new MsSqlDialect())
                                               .PageEvery(int.MaxValue)
                                               .InitializeStorageEngine()
                                               .UsingJsonSerialization()
                                               .UsingSynchronousDispatchScheduler()
                                               .DispatchTo(new MessageBusCommitDispatcher(container.Resolve <IEventDispatcher>()))
                                               .Build());
 }
Exemple #10
0
        private static IStoreEvents ConfigureEventStore()
        {
            const string CONNECTION_NAME = @"EventStore";

            var store = Wireup.Init()
                        .UsingSqlPersistence(CONNECTION_NAME)
                        .InitializeStorageEngine()
                        .UsingJsonSerialization()
                        .UsingAsynchronousDispatcher()
                        .Build();

            return(store);
        }
        public static void ClassInitialise(TestContext context)
        {
            bus = new InProcessBus(DispatchStrategy.Synchronous);

            client = new SomeAwesomeUi(bus);

            store = Wireup.Init().UsingInMemoryPersistence().Build();
            var repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector());
            var handler    = new CreateAccountCommandHandler(repository);

            bus.Subscribe(handler);
            accountId = client.CreateNewAccount();
        }
Exemple #12
0
        /// <summary>
        /// Wireup of the sql server repository
        /// </summary>
        /// <param name="wireup"></param>
        /// <returns></returns>
        private Wireup WireupAzureBlobRepository(Wireup wireup)
        {
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=bobafett;AccountKey=Kb2P5rdCo7l6hCPZCXyw2aSyL/bSabpVihORH/zuF5PUMOxt7Zz850SyC3wMetkGRyMgEh44HDo0qd9dmPNJ0Q==";
            //var connectionString = "DefaultEndpointsProtocol=https;AccountName=devtesting22;AccountKey=rbjoU5Au59V3JtHjs77hZWizhmUsadetfFTGi1L212itId3GS4Igdgq1P3Wdcr+Ojvwp06UiSheQSxdQiAlmQw==";       // evans
            var blobOptions = new AzureBlobPersistenceOptions("alphatester");
            var eventStore  = new byte[] { 80, 94, 86, 128, 97, 74, 65, 94, 91, 126, 62, 52, 129, 114, 86, 107, 80, 94, 86, 128, 97, 74, 65, 94, 91, 126, 62, 52, 129, 114, 86, 107 };

            return(wireup
                   .UsingAzureBlobPersistence(connectionString, blobOptions)
                   .InitializeStorageEngine()
                   .UsingBinarySerialization()
                   .EncryptWithAes256(eventStore));
        }
Exemple #13
0
        /// <summary>
        /// Wireup of the sql server repository
        /// </summary>
        /// <param name="wireup"></param>
        /// <returns></returns>
        private Wireup WireupAzureBlobRepository(Wireup wireup)
        {
            //var connectionString = "DefaultEndpointsProtocol=https;AccountName=bobafett;AccountKey=nOaTY+Pds2LQGm/2mW5nhi5WP4cYmip6Rg1RYHgZRhN3IbzDAfRugMafA0cqjQ49cVtd309F8+Dz9hGMH6iCuQ==";
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=devtesting22;AccountKey=rbjoU5Au59V3JtHjs77hZWizhmUsadetfFTGi1L212itId3GS4Igdgq1P3Wdcr+Ojvwp06UiSheQSxdQiAlmQw==";                   // evans
            var blobOptions      = new AzureBlobPersistenceOptions("alphatester");
            var eventStore       = new byte[] { 80, 94, 86, 128, 97, 74, 65, 94, 91, 126, 62, 52, 129, 114, 86, 107 };

            return(wireup
                   .UsingAzureBlobPersistence(connectionString, blobOptions)
                   .InitializeStorageEngine()
                   .UsingBinarySerialization()
                   .EncryptWith(eventStore));
        }
        public void DefaultRegistration_ResolvePipline_ResolvesMetadataHook()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer();

            // Act
            var result = builder.Resolve <IEnumerable <IPipelineHook> >();

            // Assert
            result.Should().NotBeNull()
            .And.HaveCount(1)
            .And.Contain(h => h.GetType() == typeof(MetadataPipelineHook));
        }
Exemple #15
0
 private static IStoreEvents WireupEventStore()
 {
     return
         (Wireup.Init()
          .LogToOutputWindow()
          .UsingInMemoryPersistence()
          .InitializeStorageEngine()
          .TrackPerformanceInstance("example")
          .UsingJsonSerialization()
          .Compress()
          .EncryptWith(EncryptionKey)
          .Build());
 }
        public EventUpconverterWireup(Wireup wireup)
            : base(wireup)
        {
            Logger.Debug(Messages.EventUpconverterRegistered);

            this.Container.Register(c =>
            {
                if (!this.assembliesToScan.Any())
                    this.assembliesToScan.AddRange(GetAllAssemblies());
                var converters = GetConverters(this.assembliesToScan);
                return new EventUpconverterPipelineHook(converters);
            });
        }
Exemple #17
0
 internal static IStoreEvents CreateLocalDbConnection()
 {
     return(Wireup.Init()
            .LogToOutputWindow()
            .UsingInMemoryPersistence()
            .UsingSqlPersistence("LocalDbWriteStore")
            .WithDialect(new MsSqlDialect())
            .EnlistInAmbientTransaction()
            .InitializeStorageEngine()
            .UsingJsonSerialization()
            //.UsingSynchronousDispatchScheduler()
            .Build());
 }
        public async Task InitializeAndWarmUp()
        {
            _outbox = new NEventStoreOutbox(Wireup.Init()
                                            .UsingSqlPersistence(ConnectionString)
                                            .WithDialect(new PostgreSqlDialect())
                                            .InitializeStorageEngine()
                                            .UsingJsonSerialization()
                                            .Build(), TimeSpan.Zero);
            var db = new TestDbContextWithOutbox(ConnectionString, _outbox);

            db.Database.CreateIfNotExists();
            await WarmUp();
        }
Exemple #19
0
        internal static IStoreEvents WireupEventStore()
        {
            return(Wireup.Init()
                   // .LogToOutputWindow(LogLevel.Verbose)
                   // .LogToConsoleWindow(LogLevel.Verbose)
                   .UsingInMemoryPersistence()
                   .InitializeStorageEngine()
#if !NETSTANDARD1_6 && !NETSTANDARD2_0
                   .TrackPerformanceInstance("example")
#endif
                   // .HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
                   .Build());
        }
        private static IStoreEvents GetEventStore(IDispatchCommits bus)
        {
            var connectionFactory =
                new ConnectionFactory(@"Data Source=.\SQLEXPRESS;Initial Catalog=SuiteEvents;Integrated Security=SSPI;",
                                      "System.Data.SqlClient");

            //.UsingSqlPersistence(connectionFactory).InitializeStorageEngine()
            return(Wireup.Init()
                   .UsingInMemoryPersistence()
                   .UsingJsonSerialization().Compress()
                   .UsingSynchronousDispatchScheduler().DispatchTo(bus)
                   .Build());
        }
Exemple #21
0
        protected override void Context()
        {
            base.Context();

            this._storeEvents = Wireup.Init().UsingInMemoryPersistence().Build();
            this._repository1 = new EventStoreRepository(this._storeEvents, new AggregateFactory(), new ConflictDetector());
            this._repository2 = new EventStoreRepository(this._storeEvents, new AggregateFactory(), new ConflictDetector());

            _aggregateId = Guid.NewGuid();
            var aggregate = new TestAggregate(_aggregateId, "my name is..");

            _repository1.Save(aggregate, Guid.NewGuid());
        }
        public RavenPersistenceWireup(
			Wireup inner,
			string connectionName,
			IDocumentSerializer serializer,
			bool consistentQueries)
            : base(inner)
        {
            this.Container.Register(c => new RavenPersistenceFactory(
                connectionName,
                serializer,
                this.Container.Resolve<TransactionScopeOption>(),
                consistentQueries).Build());
        }
Exemple #23
0
 private static IStoreEvents WireupEventStore()
 {
     return(Wireup.Init()
            .UsingSqlPersistence("EventStore")
            .InitializeStorageEngine()
            .UsingJsonSerialization()
            .Compress()
            .EncryptWith(EncryptionKey)
            .HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
            .UsingAsynchronousDispatcher()
            .PublishTo(new DelegateMessagePublisher(DispatchCommit))
            .Build());
 }
        protected override void Load(ContainerBuilder builder)
        {
            builder
            .Register(context =>
                      new DispatchCommitsToMassTransit(context.ResolveNamed <IServiceBus>("EventBus"),
                                                       LogManager.GetLogger(typeof(DispatchCommitsToMassTransit))))
            .As <IDispatchCommits>();

            if (PersistenceType == EventStorePersistenceEnum.InMemory)
            {
                builder
                .Register(context => new ConcreteEventStore(
                              Wireup.Init()
                              .UsingInMemoryPersistence()
                              .InitializeStorageEngine()
                              .UsingSynchronousDispatchScheduler()
                              .Build()))
                .As <IEventStore>()
                .SingleInstance();
            }
            else if (PersistenceType == EventStorePersistenceEnum.MongoDb)
            {
                builder.Register(context => new ConcreteEventStore(
                                     Wireup.Init()
                                     .LogTo(type => new EventStoreLog4NetLogger(type))
                                     //.LogTo(type => new Log4NetLogger(type)) - need to get assembly redirection working
                                     .UsingMongoPersistence("mongoConnectionString", new DocumentObjectSerializer())
                                     .InitializeStorageEngine()
                                     .UsingSynchronousDispatchScheduler()
                                     .DispatchTo(context.Resolve <IDispatchCommits>())
                                     .Build()))
                .As <IEventStore>()
                .SingleInstance();

                RegisterEventTypesWithMongo();
            }
            else if (PersistenceType == EventStorePersistenceEnum.SqlServer)
            {
                builder.Register(context => new ConcreteEventStore(
                                     Wireup.Init()
                                     //.LogTo(type => new EventStoreLog4NetLogger(type))
                                     .LogTo(type => new Log4NetLogger(type))
                                     .UsingSqlPersistence("sqlEventStoreConnectionString")
                                     .InitializeStorageEngine()
                                     .UsingSynchronousDispatchScheduler()
                                     .DispatchTo(context.Resolve <IDispatchCommits>())
                                     .Build()))
                .As <IEventStore>()
                .SingleInstance();
            }
        }
Exemple #25
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var readModel = new MongoUrl(ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString);

            container.Register(
                Classes
                .FromAssemblyInThisApplication()
                .BasedOn(typeof(IEventHandler <>))
                .WithServiceAllInterfaces()
                .LifestyleTransient(),

                Component
                .For <NotifyReadModelUpdates>(),

                Component
                .For <MongoDatabase>()
                .UsingFactoryMethod(k => new MongoClient(readModel).GetServer().GetDatabase(readModel.DatabaseName)),

                Component
                .For <IDispatchCommits>()
                .ImplementedBy <CommitsDispatcher>(),

                Component
                .For <IRepository>()
                .ImplementedBy <EventStoreRepository>()
                .LifeStyle.Transient,

                Component
                .For <IConstructAggregates>()
                .ImplementedBy <AggregateFactory>(),

                Component
                .For <IDetectConflicts>()
                .ImplementedBy <ConflictDetector>()
                .LifestyleTransient(),

                Component
                .For <ProjectionEngine>()
                .Start(),

                Component.For <IStoreEvents>().UsingFactoryMethod(k =>
                                                                  Wireup.Init()
                                                                  .UsingMongoPersistence("events", new DocumentObjectSerializer())
                                                                  .InitializeStorageEngine()
                                                                  .UsingSynchronousDispatchScheduler(k.Resolve <IDispatchCommits>())
                                                                  .Build()
                                                                  )
                );

            MongoDBRegistration.Register();
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="FirebirdSqlPersistenceWireup"/> class.
		/// </summary>
		/// <param name="wireup">The wireup.</param>
		/// <param name="connectionFactory">The connection factory.</param>
		public FirebirdSqlPersistenceWireup(Wireup wireup, IConnectionFactory connectionFactory)
			: base(wireup)
		{
			this.Container.Register<IContribSqlDialect>(c => null); // auto-detect
			this.Container.Register<IContribStreamIdHasher>(c => new StreamIdHasher<SHA1>());

			this.Container.Register(c => new FirebirdSqlPersistenceFactory(
				connectionFactory,
				c.Resolve<ISerialize>(),
				c.Resolve<IContribSqlDialect>(),
				c.Resolve<IContribStreamIdHasher>(),
				c.Resolve<TransactionScopeOption>(),
				this._pageSize).Build());
		}
        /// <summary>
        /// Create a new wireup.
        /// </summary>
        /// <param name="inner">The wireup to be used.</param>
        /// <param name="connectionString">The Azure blob storage connection string.</param>
        /// <param name="persistenceOptions">Options for the Azure blob storage.</param>
        public AzureBlobPersistenceWireup(Wireup inner, string connectionString, AzureBlobPersistenceOptions persistenceOptions)
            : base(inner)
        {
            Logger.Debug("Configuring Azure blob persistence engine.");

            var options = Container.Resolve <TransactionScopeOption>();

            if (options != TransactionScopeOption.Suppress)
            {
                Logger.Warn(Messages.TransactionScopeNotSupportedSettingIgnored);
            }

            Container.Register(c => new AzureBlobPersistenceFactory(connectionString, c.Resolve <ISerialize>(), persistenceOptions).Build());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FirebirdSqlPersistenceWireup"/> class.
        /// </summary>
        /// <param name="wireup">The wireup.</param>
        /// <param name="connectionFactory">The connection factory.</param>
        public FirebirdSqlPersistenceWireup(Wireup wireup, IConnectionFactory connectionFactory)
            : base(wireup)
        {
            this.Container.Register <IContribSqlDialect>(c => null);            // auto-detect
            this.Container.Register <IContribStreamIdHasher>(c => new StreamIdHasher <SHA1>());

            this.Container.Register(c => new FirebirdSqlPersistenceFactory(
                                        connectionFactory,
                                        c.Resolve <ISerialize>(),
                                        c.Resolve <IContribSqlDialect>(),
                                        c.Resolve <IContribStreamIdHasher>(),
                                        c.Resolve <TransactionScopeOption>(),
                                        this._pageSize).Build());
        }
Exemple #29
0
        public void ReplayEventsRmqTest()
        {
            var endpointResolver = MockRepository.GenerateMock <IEndpointResolver>();

            endpointResolver.Expect(r => r.Resolve("local", "local", "commands", typeof(string), RouteType.Commands)).Return(new Endpoint("rmq", "commandsExchange", "commands", true, "json"));
            endpointResolver.Expect(r => r.Resolve("local", "local", "events", typeof(TestAggregateRootNameChangedEvent), RouteType.Events)).Return(new Endpoint("rmq", "eventsExchange", "events", true, "json"));
            endpointResolver.Expect(r => r.Resolve("local", "local", "events", typeof(TestAggregateRootCreatedEvent), RouteType.Events)).Return(new Endpoint("rmq", "eventsExchange", "events", true, "json"));


            var transports = new Dictionary <string, TransportInfo> {
                { "rmq", new TransportInfo("localhost", "guest", "guest", null, "RabbitMq") }
            };
            var messagingEngine = new MessagingEngine(new TransportResolver(transports), new RabbitMqTransportFactory());


            var eventsListener      = new EventsListener();
            var localBoundedContext = LocalBoundedContext.Named("local")
                                      .PublishingEvents(typeof(TestAggregateRootNameChangedEvent), typeof(TestAggregateRootCreatedEvent)).To("events").RoutedTo("events")
                                      .ListeningCommands(typeof(string)).On("commands").RoutedFromSameEndpoint()
                                      .ListeningInfrastructureCommands().On("commands").RoutedFromSameEndpoint()
                                      .WithCommandsHandler <EsCommandHandler>()
                                      .WithEventStore(dispatchCommits => Wireup.Init()
                                                      .LogToOutputWindow()
                                                      .UsingInMemoryPersistence()
                                                      .InitializeStorageEngine()
                                                      .UsingJsonSerialization()
                                                      .UsingSynchronousDispatchScheduler()
                                                      .DispatchTo(dispatchCommits));

            using (messagingEngine)
            {
                using (
                    var engine = new CqrsEngine(messagingEngine, endpointResolver, localBoundedContext,
                                                LocalBoundedContext.Named("projections").WithProjection(eventsListener, "local")))
                {
                    var guid = Guid.NewGuid();
                    engine.SendCommand(guid + ":create", "local");
                    engine.SendCommand(guid + ":changeName:newName", "local");

                    Thread.Sleep(2000);
                    //engine.SendCommand(new ReplayEventsCommand { Destination = "events", From = DateTime.MinValue }, "local");
                    engine.ReplayEvents("local");
                    Thread.Sleep(2000);
                    Console.WriteLine("Disposing...");
                }
            }


            Assert.That(eventsListener.Handled.Count, Is.EqualTo(4), "Events were not redelivered");
        }
        /// <summary>
        /// Default constructor to initialize the policy constructor
        /// </summary>
        /// <param name="request">New policy request</param>
        public PolicyCreator(NewPolicyRequest request)
        {
            _newPolicyRequest = request;

            var builder = Wireup.UseInternalContainer().UseMessageSerialiser <JsonNetSerialiser>();

            sagaMediator   = builder.ResolveMediator();
            sagaRepository = builder.ResolveRepository();

            _guid = Guid.NewGuid();
            Console.WriteLine($"New GUID: {_guid}");

            ((ISagaMessage)_newPolicyRequest).CorrelationId = _guid;
        }
        public void UseSqlServer_Registers_SqlServerRepository()
        {
            //Arrange
            var mediatorBuilder = Wireup.UseInternalContainer()
                                  .UseSqlServer()
                                  .WithConnectionStringName("TestingConnectionString");

            // Act
            var repository = mediatorBuilder.ResolveRepository();


            // Assert
            repository.Should().BeOfType <SqlSagaRepository>();
        }
Exemple #32
0
        private static IStoreEvents CreateNEventStore(IComponentContext ctx)
        {
            var hook  = ctx.Resolve <IPipelineHook>();
            var store = Wireup.Init()
                        .HookIntoPipelineUsing(hook)
                        .UsingSqlPersistence("RobotWarEventStore")
                        .WithDialect(new MsSqlDialect())
                        //.UsingInMemoryPersistence()
                        .InitializeStorageEngine()
                        .UsingJsonSerialization()
                        .Build();

            return(store);
        }
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // Register the SignalR hubs.
            builder.RegisterHubs(Assembly.GetExecutingAssembly());

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(t => t.Name.EndsWith("Repository", StringComparison.Ordinal))
            .AsImplementedInterfaces();


            builder.RegisterType <FeatureApplicationServices>().AsImplementedInterfaces();
            builder.RegisterType <CommandSender>().As <ICommandSender>();

            var innerBuilder = new ContainerBuilder();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHubBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IHubBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IDatabaseBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IDatabaseBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHistoryBroadcasterFor).IsAssignableFrom(_)).ToArray())
            .As <IHistoryBroadcasterFor>();

            IContainer innerContainer = innerBuilder.Build();
            var        eventHandlers  = new IEventHandler[] {
                new DatabaseEventHandler(innerContainer.Resolve <IEnumerable <IDatabaseBroadcasterFor> >()),
                new HubEventHandler(innerContainer.Resolve <IEnumerable <IHubBroadcasterFor> >()),
                new HistoryEventHandler(innerContainer.Resolve <IEnumerable <IHistoryBroadcasterFor> >())
            };
            var dispatcher = new NEventStoreDispatcher(eventHandlers);

            var nEventStore =
                Wireup.Init()
                .LogToOutputWindow()
                .UsingSqlPersistence("FeatureBeeContext")
                .WithDialect(new MsSqlDialect())
                .InitializeStorageEngine()
                // .EnlistInAmbientTransaction()
                .UsingJsonSerialization()
                .UsingSynchronousDispatchScheduler()
                .DispatchTo(new DelegateMessageDispatcher(dispatcher.DispatchCommit))
                .Build();

            builder.RegisterInstance(nEventStore);
        }
        public SqlPersistenceWireup(Wireup wireup, IConnectionFactory connectionFactory)
            : base(wireup)
        {
            Logger.Debug(Messages.ConnectionFactorySpecified, connectionFactory);

            Logger.Verbose(Messages.AutoDetectDialect);
            this.Container.Register<ISqlDialect>(c => null); // auto-detect

            this.Container.Register(c => new SqlPersistenceFactory(
                connectionFactory,
                c.Resolve<ISerialize>(),
                c.Resolve<ISqlDialect>(),
                c.Resolve<TransactionScopeOption>(),
                this.pageSize).Build());
        }
        public void SimpleAggregateHasSnapshotBeforeSnapshotting()
        {
            IStoreEvents          memoryStore      = Wireup.Init().UsingInMemoryPersistence().Build();
            IConstructAggregates  aggregateFactory = new AggregateFactory();
            IEventStoreRepository repository       = new InMemoryDomainRepository(memoryStore, aggregateFactory, new CommonDomain.Core.ConflictDetector());
            Guid            aggregateID            = Guid.NewGuid();
            SimpleAggregate aggregate = new SimpleAggregate(aggregateID, DateTime.Now);

            repository.Save(aggregate, Guid.NewGuid());
            aggregate.Version.Should().Be(1);

            ISnapshot retrievedSnapshot = repository.EventStore.Advanced.GetSnapshot(aggregate.Id, int.MaxValue);

            retrievedSnapshot.Should().BeNull();
        }
Exemple #36
0
 protected override void Context()
 {
     _eventStore = Wireup
                   .Init()
                   .UsingSqlPersistence(new EnviromentConnectionFactory("MsSql", "System.Data.SqlClient"))
                   .WithDialect(new MsSqlDialect())
                   .WithStreamIdHasher(streamId =>
     {
         _hasherInvoked = true;
         return(new Sha1StreamIdHasher().GetHash(streamId));
     })
                   .InitializeStorageEngine()
                   .UsingBinarySerialization()
                   .Build();
 }
Exemple #37
0
        private IStoreEvents WireupEventStore(string dillyDallyStoreConnectionString)
        {
            var store = Wireup.Init()
                        .UsingSqlPersistence(new SQLiteFactory(), dillyDallyStoreConnectionString)
                        .WithDialect(new SqliteDialect())
                        .InitializeStorageEngine()
                        .UsingJsonSerialization()
                        .Compress()
                        .EncryptWith(EncryptionKey)
                        .LogToOutputWindow(LogLevel.Debug)
                        .HookIntoPipelineUsing(new AuthorizationPipelineHook())
                        .Build();

            return(store);
        }
 public IStoreEvents Build(Type aggregateType)
 {
     lock ( _eventStores )
     {
         if (!_eventStores.ContainsKey(aggregateType))
         {
             var eventStore = Wireup.Init()
                              .UsingInMemoryPersistence()
                              .InitializeStorageEngine()
                              .Build();
             _eventStores.Add(aggregateType, eventStore);
         }
         return(_eventStores[aggregateType]);
     }
 }
Exemple #39
0
        public static void AddEventStore(this IServiceCollection serviceCollection, LogLevel logLevel = LogLevel.Info, string connectionStringName = "EventStoreDatabase")
        {
            var connectionString = serviceCollection.GetConnectionString(connectionStringName);

            serviceCollection.AddTransient(typeof(IRepository <>), typeof(AggregateRepository <>));

            serviceCollection.AddTransient <IStoreEvents>(service => Wireup
                                                          .Init()
                                                          .LogToConsoleWindow(logLevel)
                                                          .UsingSqlPersistence(SqlClientFactory.Instance, connectionString)
                                                          .WithDialect(new NEventStore.Persistence.Sql.SqlDialects.MsSqlDialect())
                                                          .InitializeStorageEngine()
                                                          .UsingJsonSerialization()
                                                          .Build());
        }
        public EventStore()
        {
            _store = Wireup.Init()
                     //uncomment these lines to enable SQL Server as a datastore
                     //Also, put your SQL Server connectionstring in App.config

                     //.UsingSqlPersistence("SqlConnectionString")
                     //.WithDialect(new MsSqlDialect())

                     //comment when using another datastore
                     .UsingInMemoryPersistence()
                     .InitializeStorageEngine()
                     .UsingJsonSerialization()
                     .Build();
        }
Exemple #41
0
 private static IStoreEvents WireupEventStore()
 {
     return(Wireup.Init()
            .LogToOutputWindow()
            .UsingInMemoryPersistence()
            .InitializeStorageEngine()
            .TrackPerformanceInstance("example")
            .UsingJsonSerialization()
            .Compress()
            .EncryptWith(EncryptionKey)
            .HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
            .UsingSynchronousDispatchScheduler()
            .DispatchTo(new DelegateMessageDispatcher(DispatchCommit))
            .Build());
 }
Exemple #42
0
        public void AddingPipeline_Adds_ToCollection()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly())
                          .AddPiplineHook <NullPipelineHook>();

            // Act
            var result = builder.Resolve <IEnumerable <IPipelineHook> >();

            // Assert
            result.Should().NotBeNull()
            .And.HaveCount(2)
            .And.Contain(h => h.GetType() == typeof(MetadataPipelineHook))
            .And.Contain(h => h.GetType() == typeof(NullPipelineHook));
        }
Exemple #43
0
        public NESWireup(Wireup wireup)
            : base(wireup)
        {
            _logger.Debug("Configuring serializer to cope with payloads that contain messages as interfaces.");
            _logger.Debug("Wrapping serializer of type '" + Container.Resolve<ISerialize>().GetType() + "' in '" + typeof(Serializer) + "'");

            Container.Register<ISerialize>(new Serializer(Container.Resolve<ISerialize>(), () => DI.Current.Resolve<IEventSerializer>()));

            _logger.Debug("Configuring the store to dispatch messages synchronously.");
            _logger.Debug("Registering dispatcher of type '" + typeof(MessageDispatcher) + "'.");

            Container.Register<IScheduleDispatches>(c => new SynchronousDispatchScheduler(new MessageDispatcher(() => DI.Current.Resolve<IEventPublisher>()), c.Resolve<IPersistStreams>()));

            DI.Current.Register<IEventStore, IStoreEvents>(eventStore => new EventStoreAdapter(eventStore));
            DI.Current.Register(() => Container.Resolve<IStoreEvents>());
        }
        public SqlPersistenceWireup(Wireup wireup, IConnectionFactory connectionFactory)
            : base(wireup)
        {
            Logger.Debug(Messages.ConnectionFactorySpecified, connectionFactory);

            Logger.Verbose(Messages.AutoDetectDialect);
            Container.Register<ISqlDialect>(c => null); // auto-detect
            Container.Register<IStreamIdHasher>(c => new Sha1StreamIdHasher());

            Container.Register(c => new SqlPersistenceFactory(
                connectionFactory,
                new ReadAheadJsonSerializer(), 
                c.Resolve<ISqlDialect>(),
                c.Resolve<IStreamIdHasher>(),
                c.Resolve<TransactionScopeOption>(),
                _pageSize).Build());
        }
 public SynchronousDispatchSchedulerWireup(Wireup wireup, IDispatchCommits dispatcher, DispatcherSchedulerStartup schedulerStartup)
     : base(wireup)
 {
     Logger.Debug(Messages.SyncDispatchSchedulerRegistered);
     DispatchTo(dispatcher ?? new NullDispatcher());
     Container.Register<IScheduleDispatches>(c =>
     {
         var dispatchScheduler = new SynchronousDispatchScheduler(
             c.Resolve<IDispatchCommits>(),
             c.Resolve<IPersistStreams>());
         if (schedulerStartup == DispatcherSchedulerStartup.Auto)
         {
             dispatchScheduler.Start();
         }
         return dispatchScheduler;
     });
 }
        public RavenPersistenceWireup(Wireup inner, string connectionName)
            : base(inner)
        {
            this.Container.Register(c => new RavenConfiguration
            {
                Serializer = this.ResolveSerializer(c),
                ScopeOption = c.Resolve<TransactionScopeOption>(),
                ConsistentQueries = this.consistentQueries,
                MaxServerPageSize = this.maxServerPageSize,
                RequestedPageSize = this.pageSize,
                ConnectionName = connectionName,
                DefaultDatabase = this.defaultDatabase,
                Url = this.url
            });

            this.Container.Register(c => new RavenPersistenceFactory(c.Resolve<RavenConfiguration>()).Build());
        }
        public RavenPersistenceWireup(Wireup inner)
            : base(inner)
        {
            Logger.Debug("Configuring Raven persistence engine.");

            this.Container.Register(c => new RavenConfiguration
            {
                Serializer = this.ResolveSerializer(c),
                ScopeOption = c.Resolve<TransactionScopeOption>(),
                ConsistentQueries = this.consistentQueries,
                MaxServerPageSize = this.maxServerPageSize,
                RequestedPageSize = this.pageSize,
                Partition = this.partition,
            });

            this.Container.Register<IPersistStreams>(c => new RavenPersistenceEngine(getStoreAction(), c.Resolve<RavenConfiguration>()));
        }
        public AsynchronousDispatchSchedulerWireup(Wireup wireup, IDispatchCommits dispatcher, DispatcherSchedulerStartup schedulerStartup)
            : base(wireup)
        {
            var option = Container.Resolve<TransactionScopeOption>();
            if (option != TransactionScopeOption.Suppress)
            {
                Logger.Warn(Messages.SynchronousDispatcherTwoPhaseCommits);
            }

            Logger.Debug(Messages.AsyncDispatchSchedulerRegistered);
            DispatchTo(dispatcher ?? new NullDispatcher());
            Container.Register<IScheduleDispatches>(c =>
            {
                var dispatchScheduler = new AsynchronousDispatchScheduler(
                    c.Resolve<IDispatchCommits>(),
                    c.Resolve<IPersistStreams>());
                if (schedulerStartup == DispatcherSchedulerStartup.Auto)
                {
                    dispatchScheduler.Start();
                }
                return dispatchScheduler;
            });
        }
        public RavenPersistenceWireup(Wireup inner, string connectionName)
            : base(inner)
        {
            Logger.Debug("Configuring Raven persistence engine.");

            this.connectionName = connectionName;

            this.Container.Register(c => new RavenConfiguration
            {
                Serializer = this.ResolveSerializer(c),
                ScopeOption = c.Resolve<TransactionScopeOption>(),
                ConsistentQueries = this.consistentQueries,
                MaxServerPageSize = this.maxServerPageSize,
                RequestedPageSize = this.pageSize,
                ConnectionName = this.connectionName,
                ConnectionString = this.connectionString,
                DefaultDatabase = this.defaultDatabase,
                Url = this.url,
                Partition = this.partition,
                CustomizeConventions = this.customizeConventions
            });

            this.Container.Register(c => new RavenPersistenceFactory(c.Resolve<RavenConfiguration>()).Build());
        }
Exemple #50
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup
         .UsingSqlPersistence("PostgreSql")
         .WithDialect(new PostgreSqlDialect());
 }
 public HookWireup(Wireup inner)
     : base(inner)
 {
 }
Exemple #52
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup
         .UsingSqlPersistence("SqlServer")
         .WithDialect(new MsSqlDialect());
 }
 public RavenPersistenceWireup(Wireup inner, Func<IDocumentStore> getStore)
     : this(inner)
 {
     getStoreAction = getStore;
 }
 public RavenPersistenceWireup(Wireup inner, string connectionName)
     : this(inner)
 {
     getStoreAction = CreateStore;
     CreateWithConnectionStringName(connectionName);
 }
Exemple #55
0
 protected abstract PersistenceWireup ConfigurePersistence(Wireup wireup);
 public RavenPersistenceWireup(Wireup inner)
     : this(inner, string.Empty)
 {
 }
Exemple #57
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup.UsingRavenPersistence("Raven");
 }
Exemple #58
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup.UsingMongoPersistence("Mongo", new DocumentObjectSerializer());
 }
Exemple #59
0
 public MongoPersistenceWireupFromConnectionString(Wireup inner, string connectionString, IDocumentSerializer serializer)
     : base(inner)
 {
     Logger.Debug("Configuring Mongo persistence engine.");
     Container.Register(c => new MongoPersistenceFactoryFromConnectionString(connectionString, serializer).Build());
 }
 protected override void Context()
 {
     _wireup = Wireup.Init()
         .UsingSqlPersistence("fakeConnectionString")
             .WithDialect(new Persistence.Sql.SqlDialects.MsSqlDialect());
 }