Пример #1
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.CreatePatching();
            options.Validate();

            Options      = options;
            _logger      = options.Logger();
            Serializer   = options.Serializer();
            _retryPolicy = options.RetryPolicy();

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            Tenancy.Initialize();

            Schema = Tenancy.Schema;

            Storage.PostProcessConfiguration();

            Advanced = new AdvancedOptions(this);

            Diagnostics = new Diagnostics(this);

            Transform = new DocumentTransforms(this, Tenancy.Default);

            options.InitialData.Each(x => x.Populate(this));
        }
Пример #2
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.CreatePatching();

            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);

            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);


            CreateDatabaseObjects();

            Transform = new DocumentTransforms(this, _connectionFactory);

            options.InitialData.Each(x => x.Populate(this));


            if (options.AutoCreateSchemaObjects != AutoCreate.None)
            {
                Schema.As <DocumentSchema>().RebuildSystemFunctions();
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();
            _runner            = new ManagedConnection(_connectionFactory, CommandRunnerMode.ReadOnly);

            _logger = options.Logger();

            var creation = options.AutoCreateSchemaObjects
                ? (IDocumentSchemaCreation) new DevelopmentSchemaCreation(_connectionFactory, _logger)
                : new ProductionSchemaCreation();

            Schema = new DocumentSchema(_options, _connectionFactory, creation);

            Schema.Alter(options.Schema);

            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema);

            Advanced = new AdvancedOptions(cleaner, options);

            Diagnostics = new Diagnostics(Schema, new MartenQueryExecutor(_runner, Schema, _serializer, _parser, new NulloIdentityMap(_serializer)));

            EventStore = new EventStoreAdmin(_connectionFactory, _options, creation, _serializer);
        }
Пример #4
0
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.Validate();

            Options    = options;
            _logger    = options.Logger();
            Serializer = options.Serializer();

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            Schema = Tenancy.Default.Database;

            Storage.PostProcessConfiguration();
            Events.AssertValidity(this);
            Options.Projections.AssertValidity(this);

            Advanced = new AdvancedOperations(this);

            Diagnostics = new Diagnostics(this);

            if (Options.GeneratedCodeMode == TypeLoadMode.LoadFromPreBuiltAssembly)
            {
                var rules = new GenerationRules(SchemaConstants.MartenGeneratedNamespace);
                Events.As <IGeneratesCode>().AttachPreBuiltTypes(rules, Assembly.GetEntryAssembly(), null);

                Options.As <IGeneratesCode>().AttachPreBuiltTypes(rules, Assembly.GetEntryAssembly(), null);
            }

            options.InitialData.Each(x => x.Populate(this).GetAwaiter().GetResult());
        }
Пример #5
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);


            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);


            CreateDatabaseObjects();

            Transform = new DocumentTransforms(this);

            options.InitialData.Each(x => x.Populate(this));
        }
Пример #6
0
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.Validate();

            Options      = options;
            _logger      = options.Logger();
            Serializer   = options.Serializer();
            _retryPolicy = options.RetryPolicy();

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            //Tenancy.Initialize();

            Schema = Tenancy.Schema;

            Storage.PostProcessConfiguration();
            Events.AssertValidity(this);
            Options.Projections.AssertValidity(this);

            Advanced = new AdvancedOperations(this);

            Diagnostics = new Diagnostics(this);

            options.InitialData.Each(x => x.Populate(this).GetAwaiter().GetResult());
        }
Пример #7
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.CreatePatching();
            options.Validate();
            Options = options;

            _logger = options.Logger();

            Tenancy = options.Tenancy;

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            Tenancy.Initialize();

            Schema = Tenancy.Schema;

            Storage = options.Storage;

            Storage.PostProcessConfiguration();

            Serializer = options.Serializer();

            if (options.UseCharBufferPooling)
            {
                _writerPool = new CharArrayTextWriter.Pool();
            }

            Advanced = new AdvancedOptions(this);

            Diagnostics = new Diagnostics(this);

            Transform = new DocumentTransforms(this, Tenancy.Default);

            options.InitialData.Each(x => x.Populate(this));

            Parser = new MartenExpressionParser(Serializer, options);

            HandlerFactory = new QueryHandlerFactory(this);

            Events = options.Events;
        }
        /// <summary>
        /// Add Marten IDocumentStore, IDocumentSession, and IQuerySession service registrations
        /// to your application using the configured StoreOptions
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options">The Marten configuration for this application</param>
        /// <returns></returns>
        public static MartenConfigurationExpression AddMarten(this IServiceCollection services, StoreOptions options)
        {
            services.AddSingleton <IDocumentStore>(s =>
            {
                var logger = s.GetService <ILogger <IDocumentStore> >() ?? new NullLogger <IDocumentStore>();
                options.Logger(new DefaultMartenLogger(logger));

                return(new DocumentStore(options));
            });

            // This can be overridden by the expression following
            services.AddSingleton <ISessionFactory, DefaultSessionFactory>();


            services.AddScoped(s => s.GetRequiredService <ISessionFactory>().QuerySession());
            services.AddScoped(s => s.GetRequiredService <ISessionFactory>().OpenSession());

            switch (options.Events.Daemon.Mode)
            {
            case DaemonMode.Disabled:
                // Nothing
                break;

            case DaemonMode.Solo:
                services.AddSingleton <INodeCoordinator, SoloCoordinator>();
                services.AddSingleton(x =>
                                      x.GetRequiredService <IDocumentStore>()
                                      .BuildProjectionDaemon(x.GetRequiredService <ILogger <IProjectionDaemon> >()));
                services.AddHostedService <AsyncProjectionHostedService>();
                break;

            case DaemonMode.HotCold:
                services.AddSingleton <INodeCoordinator, HotColdCoordinator>();
                services.AddSingleton(x =>
                                      x.GetRequiredService <IDocumentStore>()
                                      .BuildProjectionDaemon(x.GetRequiredService <ILogger <IProjectionDaemon> >()));
                services.AddHostedService <AsyncProjectionHostedService>();
                break;
            }

            return(new MartenConfigurationExpression(services, options));
        }
Пример #9
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.Validate();
            options.CreatePatching();

            Options = options;

            _logger = options.Logger();

            Tenancy = options.Tenancy;
            Tenancy.Initialize();

            Schema = Tenancy.Schema;

            Storage = options.Storage;

            Storage.CompileSubClasses();

            Serializer = options.Serializer();

            if (options.UseCharBufferPooling)
            {
                _writerPool = new CharArrayTextWriter.Pool();
            }

            Advanced = new AdvancedOptions(this);

            Diagnostics = new Diagnostics(this);

            Transform = new DocumentTransforms(this, Tenancy.Default);

            options.InitialData.Each(x => x.Populate(this));

            Parser = new MartenExpressionParser(Serializer, options);

            HandlerFactory = new QueryHandlerFactory(this);

            Events = options.Events;
        }
Пример #10
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);


            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);

            EventStore = new EventStoreAdmin(Schema, _connectionFactory, _options, _serializer);

            CreateDatabaseObjects();
        }
Пример #11
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.CreatePatching();
            options.Validate();

            Options      = options;
            _logger      = options.Logger();
            Serializer   = options.Serializer();
            _retryPolicy = options.RetryPolicy();

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            Tenancy.Initialize();

            Schema = Tenancy.Schema;

            Storage.PostProcessConfiguration();

            _writerPool = options.UseCharBufferPooling ? MemoryPool <char> .Shared : new AllocatingMemoryPool <char>();

            Advanced = new AdvancedOptions(this);

            Diagnostics = new Diagnostics(this);

            Transform = new DocumentTransforms(this, Tenancy.Default);

            Parser = new MartenExpressionParser(Serializer, options);

            HandlerFactory = new QueryHandlerFactory(this);

            options.InitialData.Each(x => x.Populate(this));
        }
Пример #12
0
        public DocumentStore(StoreOptions options)
        {
            options.ApplyConfiguration();
            options.Validate();

            Options    = options;
            _logger    = options.Logger();
            Serializer = options.Serializer();


            // Workaround to make database creation lazy so all StoreOptions
            // customizations can be done first
            if (Tenancy is DefaultTenancy d)
            {
                d.Initialize();
            }

            if (options.CreateDatabases != null)
            {
                IDatabaseGenerator databaseGenerator = new DatabaseGenerator();
                databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases);
            }

            StorageFeatures.PostProcessConfiguration();
            Events.AssertValidity(this);
            Options.Projections.AssertValidity(this);

            Advanced = new AdvancedOperations(this);

            Diagnostics = new Diagnostics(this);

            _lightweightCompiledQueries  = new CompiledQueryCollection(DocumentTracking.None, this);
            _identityMapCompiledQueries  = new CompiledQueryCollection(DocumentTracking.IdentityOnly, this);
            _dirtyTrackedCompiledQueries = new CompiledQueryCollection(DocumentTracking.DirtyTracking, this);
            _queryOnlyCompiledQueries    = new CompiledQueryCollection(DocumentTracking.QueryOnly, this);
        }