public static PersistenceWireup UsingMongoPersistence(this Wireup wireup, string connectionName, IDocumentSerializer serializer, MongoPersistenceOptions options = null)
		{
			return new MongoPersistenceWireup(wireup, () =>
			{
			    var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];
                if( connectionStringSettings == null)
                    throw new ConfigurationErrorsException(Messages.ConnectionNotFound.FormatWith(connectionName));

			    return connectionStringSettings.ConnectionString;
			}, serializer, options);
		}
        public MongoPersistenceWireup(Wireup inner, Func<string> connectionStringProvider, IDocumentSerializer serializer, MongoPersistenceOptions persistenceOptions)
            : 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(connectionStringProvider, serializer, persistenceOptions).Build());
        }
示例#3
0
        public MongoPersistenceEngine(MongoDatabase store, IDocumentSerializer serializer, MongoPersistenceOptions options)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _store      = store;
            _serializer = serializer;
            _options    = options;

            // set config options
            _commitSettings           = _options.GetCommitSettings();
            _snapshotSettings         = _options.GetSnapshotSettings();
            _streamSettings           = _options.GetStreamSettings();
            _insertCommitWriteConcern = _options.GetInsertCommitWriteConcern();

            _getLastCheckPointNumber = () => TryMongo(() =>
            {
                var max = PersistedCommits
                          .FindAll()
                          .SetFields(Fields.Include(MongoCommitFields.CheckpointNumber))
                          .SetSortOrder(SortBy.Descending(MongoCommitFields.CheckpointNumber))
                          .SetLimit(1)
                          .FirstOrDefault();

                return(max != null ? max[MongoCommitFields.CheckpointNumber].AsInt64 : 0L);
            });

            _getNextCheckpointNumber = () => new LongCheckpoint(_getLastCheckPointNumber() + 1L);

            _updateScript   = new BsonJavaScript("function (x){ return insertCommit(x);}");
            _checkpointZero = new LongCheckpoint(0);
        }
		public static PersistenceWireup UsingMongoPersistence(this Wireup wireup, Func<string> connectionStringProvider, IDocumentSerializer serializer, MongoPersistenceOptions options = null)
		{
			return new MongoPersistenceWireup(wireup, connectionStringProvider, serializer, options);
		}
	    public MongoPersistenceFactory(Func<string> connectionStringProvider, IDocumentSerializer serializer, MongoPersistenceOptions options = null)
        {
            _connectionStringProvider = connectionStringProvider;
            _serializer = serializer;
	        _options = options ?? new MongoPersistenceOptions();
        }
示例#6
0
 public MongoPersistenceFactory(Func <string> connectionStringProvider, IDocumentSerializer serializer, MongoPersistenceOptions options = null)
 {
     _connectionStringProvider = connectionStringProvider;
     _serializer = serializer;
     _options    = options ?? new MongoPersistenceOptions();
 }
 public static PersistenceWireup UsingMongoPersistence(this Wireup wireup, string connectionName, IDocumentSerializer serializer, MongoPersistenceOptions options = null)
 {
     return new MongoPersistenceWireup(wireup, () => ConfigurationManager.ConnectionStrings[connectionName].ConnectionString, serializer, options);
 }
        private void RegisterTenantServices()
        {
            foreach (var tenant in _manager.Tenants)
            {
                ITenant tenant1 = tenant;

                var esComponentName = tenant.Id + "-es";
                var readModelDb = tenant1.Get<IMongoDatabase>("readmodel.db");

                var mongoPersistenceOptions = new MongoPersistenceOptions();
                mongoPersistenceOptions.DisableSnapshotSupport = true;
                mongoPersistenceOptions.ConcurrencyStrategy = ConcurrencyExceptionStrategy.FillHole;
                var nesUrl = new MongoUrl(tenant1.GetConnectionString("events"));
                var nesDb = new MongoClient(nesUrl).GetDatabase(nesUrl.DatabaseName);
                var eventsCollection = nesDb.GetCollection<BsonDocument>("Commits");
                mongoPersistenceOptions.CheckpointGenerator = new InMemoryCheckpointGenerator(eventsCollection);

                tenant1.Container.Register(
                            Classes
                                .FromAssemblyContaining<DocumentDescriptor>()
                                .BasedOn<IPipelineHook>()
                                .WithServiceAllInterfaces(),
                            Component
                                .For<IStoreEvents>()
                                .Named(esComponentName)
                                .UsingFactory<EventStoreFactory, IStoreEvents>(f =>
                                {
                                    var hooks = tenant1.Container.ResolveAll<IPipelineHook>();

                                    return f.BuildEventStore(
                                            tenant1.GetConnectionString("events"),
                                            hooks,
                                            mongoPersistenceOptions : mongoPersistenceOptions
                                        );
                                })
                                .LifestyleSingleton(),

                            Component
                                .For<IRepositoryEx, RepositoryEx>()
                                .ImplementedBy<RepositoryEx>()
                                .Named(tenant.Id + ".repository")
                                .DependsOn(Dependency.OnComponent(typeof(IStoreEvents), esComponentName))
                                .LifestyleTransient(),

                            Component
                                .For<Func<IRepositoryEx>>()
                                .Instance(() => tenant1.Container.Resolve<IRepositoryEx>()),
                            Component
                                .For<ISnapshotManager>()
                                .DependsOn(Dependency.OnValue("cacheEnabled", _config.EnableSnapshotCache))
                                .ImplementedBy<CachedSnapshotManager>(),
                            Component
                                .For<IAggregateCachedRepositoryFactory>()
                                .ImplementedBy<AggregateCachedRepositoryFactory>()
                                .DependsOn(Dependency.OnValue("cacheDisabled", false)),
                            Component
                                .For<ISnapshotPersistenceStrategy>()
                                .ImplementedBy<NumberOfCommitsShapshotPersistenceStrategy>()
                                .DependsOn(Dependency.OnValue("commitsThreshold", 100)),
                             Component.For<ISnapshotPersister>()
                                    .ImplementedBy<MongoSnapshotPersisterProvider>()
                                    .DependsOn(Dependency.OnValue<IMongoDatabase>(readModelDb))
                            );
            }
        }