Esempio n. 1
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For <IBus, IDispatchCommits>().ImplementedBy <InMemoryBus>().LifestyleSingleton());
            container.Register(
                Classes
                .FromAssemblyContaining <ToDoEventsConverters>()
                .BasedOn(typeof(IUpconvertEvents <,>)) // That implement ICommandHandler Interface
                .WithService.Base()
                .LifestyleTransient());

            //#region Work-Around for Event-Upconverion with SynchronousDispatchScheduler
            //IDictionary<Type, Func<object, object>> _registered = new Dictionary<Type, Func<object, object>>();
            //var converter = new ToDoEventsConverters();
            //_registered[typeof (AddedNewToDoItemEvent_V0)] = @event => converter.Convert(@event as AddedNewToDoItemEvent_V0);
            //// Workaround for Events Up-conversion. InMemoryBus is injected with EventUpconverterPipelineHook instance.
            ////container.Register(Component.For<EventUpconverterPipelineHook>().Instance(new EventUpconverterPipelineHook(_registered)));
            //#endregion

            _store =
                Wireup
                .Init()
                .LogToOutputWindow()
                .UsingInMemoryPersistence()
                .UsingSqlPersistence("EventStore")     // Connection string is in web.config
                .WithDialect(new MsSqlDialect())
                //.UsingJsonSerialization()
                .UsingNewtonsoftJsonSerialization(new VersionedEventSerializationBinder())
                // Compress Aggregate serialization. Does NOT allow to do a SQL-uncoding of varbinary Payload
                // Comment if you need to decode message with CAST([Payload] AS VARCHAR(MAX)) AS [Payload] (on some VIEW)
                //.Compress()
                .UsingSynchronousDispatchScheduler()
                .DispatchTo(container.Resolve <IDispatchCommits>())
                .Startup(DispatcherSchedulerStartup.Explicit)
                //// DOES NOT WORK WITH SynchronousDispatchScheduler
                .UsingEventUpconversion()
                .WithConvertersFromAssemblyContaining(new Type[] { typeof(ToDoEventsConverters) })
                //    .AddConverter<AddedNewToDoItemEvent_V0, AddedNewToDoItemEvent>(new ToDoEventsConverters())
                //.HookIntoPipelineUsing(new EventUpconverterPipelineHook(_registered))
                //.WithConvertersFromAssemblyContaining(new Type[]{typeof(ToDoEventsConverters)})
                .Build();

            _store.StartDispatchScheduler();

            //wireup.AddConverter(new ToDoEventsConverters());
            //_store = wireup.Build();

            container.Register(
                Component.For <IStoreEvents>().Instance(_store),
                Component.For <IRepository>().ImplementedBy <EventStoreRepository>().LifeStyle.Transient,
                Component.For <IConstructAggregates>().ImplementedBy <AggregateFactory>().LifeStyle.Transient,
                Component.For <IDetectConflicts>().ImplementedBy <ConflictDetector>().LifeStyle.Transient);


            //// Elegant way to write the same Registration as before:
            //container.Register(
            //    Component.For<IStoreEvents>().Instance(_store),
            //    C<IRepository, EventStoreRepository>(),
            //    C<IConstructAggregates, AggregateFactory>(),
            //    C<IDetectConflicts, ConflictDetector>());
        }
Esempio n. 2
0
 protected override void Because()
 {
     _eventStore.StartDispatchScheduler();
     using (var stream = _eventStore.OpenStream(Guid.NewGuid()))
     {
         stream.Add(new EventMessage {
             Body = "Body"
         });
         stream.CommitChanges(Guid.NewGuid());
     }
 }
Esempio n. 3
0
        //private void SubscribeEvents(IBus bus)
        //{
        //    bus.Subscribe<ToDoEventHandlers>();
        //}

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For <IBus, IDispatchCommits>().ImplementedBy <InMemoryBus>().LifestyleSingleton());
            container.Register(
                Classes
                .FromAssemblyContaining <SavedNewDraftLessonEvent>()
                .BasedOn(typeof(IUpconvertEvents <,>)) // That implement IUpconvertEvents<,> Interface
                .WithService.Base()
                .LifestyleTransient());

            _store =
                Wireup
                .Init()
                .LogToOutputWindow()
                .UsingInMemoryPersistence()
                .UsingSqlPersistence("EventStore")     // Connection string is in web.config
                .WithDialect(new MsSqlDialect())
                .InitializeStorageEngine()
                //.UsingJsonSerialization()
                .UsingNewtonsoftJsonSerialization(new VersionedEventSerializationBinder())
                .Compress()
                .UsingSynchronousDispatchScheduler()
                .DispatchTo(container.Resolve <IDispatchCommits>())
                .Startup(DispatcherSchedulerStartup.Explicit)
                .UsingEventUpconversion()
                .WithConvertersFromAssemblyContaining(new Type[] { typeof(SavedNewDraftLessonEvent) })
                .Build();

            _store.StartDispatchScheduler();

            container.Register(
                Component.For <IStoreEvents>().Instance(_store),
                Component.For <IRepository>().ImplementedBy <EventStoreRepository>().LifeStyle.Transient,
                Component.For <ISagaRepository>().ImplementedBy <SagaEventStoreRepository>().LifeStyle.Transient,
                Component.For <ISagaIdStore>().ImplementedBy <InMemorySagaIdStore>().LifeStyle.Transient,
                Component.For <IConstructAggregates>().ImplementedBy <AggregateFactory>().LifeStyle.Transient,
                Component.For <IDetectConflicts>().ImplementedBy <ConflictDetector>().LifeStyle.Transient);

            //// Elegant way to write the same Registration as before:
            //container.Register(
            //    Component.For<IStoreEvents>().Instance(_store),
            //    C<IRepository, EventStoreRepository>(),
            //    C<IConstructAggregates, AggregateFactory>(),
            //    C<IDetectConflicts, ConflictDetector>());
        }