コード例 #1
0
        /// <summary>
        /// Use MongoDb with a one or multiple server urls.
        /// Multiples urls are usefull when a replica set has been created.
        /// </summary>
        /// <param name="bootstrapper">Bootstrapper instance.</param>
        /// <param name="options">Options to bootstrap MongoDb as Event Store.</param>
        /// <returns>Bootstrapper instance.</returns>
        public static Bootstrapper UseMongoDbAsEventStore(this Bootstrapper bootstrapper, MongoEventStoreOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var service = new MongoDbEventStoreBootstrappService
                              (ctx =>
            {
                BsonSerializer.RegisterSerializer(typeof(Type), new TypeSerializer());
                BsonSerializer.RegisterSerializer(typeof(Guid), new GuidSerializer());
                BsonSerializer.RegisterSerializer(typeof(object), new ObjectSerializer());
                EventStoreManager.Options = options;
                if (options.SnapshotBehaviorProvider != null)
                {
                    if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC))
                    {
                        bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(options.SnapshotBehaviorProvider, typeof(ISnapshotBehaviorProvider)));
                        bootstrapper.AddIoCRegistration(new FactoryRegistration(
                                                            () => new MongoDbEventStore(options.SnapshotBehaviorProvider, options.SnapshotEventsArchiveBehavior),
                                                            typeof(MongoDbEventStore), typeof(IWriteEventStore)));
                    }
                }
                EventStoreManager.Activate();
            }
                              );

            bootstrapper.AddService(service);
            return(bootstrapper);
        }
コード例 #2
0
ファイル: Bootstrapper.ext.cs プロジェクト: sputier/CQELight
        /// <summary>
        /// Use EF Core as EventStore for system, with the provided connection string.
        /// This is a usable case for common cases, in system that not have a huge amount of events, or for test/debug purpose.
        /// This is not recommanded for real-world big applications case.
        /// </summary>
        /// <param name="bootstrapper">Bootstrapper instance.</param>
        /// <param name="options">Options to use to configure event store.</param>
        /// <returns>Bootstrapper instance</returns>
        public static Bootstrapper UseEFCoreAsEventStore(this Bootstrapper bootstrapper, EFEventStoreOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var service = new EFEventStoreBootstrappService
            {
                BootstrappAction = (ctx) =>
                {
                    if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC))
                    {
                        bootstrapper.AddIoCRegistration(new FactoryRegistration(() =>
                                                                                new EventStoreDbContext(options.DbContextOptions, options.ArchiveBehavior), typeof(EventStoreDbContext)));
                        bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(EFEventStore), true));
                        bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(options, typeof(EFEventStoreOptions)));
                        if (options.SnapshotBehaviorProvider != null)
                        {
                            bootstrapper.AddIoCRegistration(
                                new InstanceTypeRegistration(options.SnapshotBehaviorProvider, typeof(ISnapshotBehaviorProvider)));
                        }
                        if (options.ArchiveBehavior == EventStore.SnapshotEventsArchiveBehavior.StoreToNewDatabase &&
                            options.ArchiveDbContextOptions != null)
                        {
                            bootstrapper.AddIoCRegistration(new FactoryRegistration(() =>
                                                                                    new ArchiveEventStoreDbContext(options.ArchiveDbContextOptions), typeof(ArchiveEventStoreDbContext)));
                        }
                    }
                    EventStoreManager.s_Options = options;
                    EventStoreManager.Activate();
                }
            };

            bootstrapper.AddService(service);
            return(bootstrapper);
        }