diff --git a/src/AspNetCoreWithMarten/Samples/ByNestedClosure/Startup.cs b/src/AspNetCoreWithMarten/Samples/ByNestedClosure/Startup.cs index 4109c88efa..03b512061b 100644 --- a/src/AspNetCoreWithMarten/Samples/ByNestedClosure/Startup.cs +++ b/src/AspNetCoreWithMarten/Samples/ByNestedClosure/Startup.cs @@ -1,3 +1,5 @@ +using JasperFx; +using JasperFx.CodeGeneration; using Marten; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -25,13 +27,17 @@ public void ConfigureServices(IServiceCollection services) var connectionString = Configuration.GetConnectionString("postgres"); services.AddMarten(opts => - { - opts.Connection(connectionString); - }) - // Using the "Optimized artifact workflow" for Marten >= V5 - // sets up your Marten configuration based on your environment - // See https://martendb.io/configuration/optimized_artifact_workflow.html - .OptimizeArtifactWorkflow(); + { + opts.Connection(connectionString); + }); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); #endregion } diff --git a/src/AspNetCoreWithMarten/Samples/ByStoreOptions/Startup.cs b/src/AspNetCoreWithMarten/Samples/ByStoreOptions/Startup.cs index ca443d2916..eaf68b5e74 100644 --- a/src/AspNetCoreWithMarten/Samples/ByStoreOptions/Startup.cs +++ b/src/AspNetCoreWithMarten/Samples/ByStoreOptions/Startup.cs @@ -1,3 +1,5 @@ +using JasperFx; +using JasperFx.CodeGeneration; using Marten; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -27,12 +29,13 @@ public void ConfigureServices(IServiceCollection services) var options = new StoreOptions(); options.Connection(connectionString); - - services.AddMarten(options) - // Using the "Optimized artifact workflow" for Marten >= V5 - // sets up your Marten configuration based on your environment - // See https://martendb.io/configuration/optimized_artifact_workflow.html - .OptimizeArtifactWorkflow(); + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); #endregion } diff --git a/src/AspNetCoreWithMarten/Samples/ConfiguringSessionCreation/Startup.cs b/src/AspNetCoreWithMarten/Samples/ConfiguringSessionCreation/Startup.cs index 8b985582e7..6d3499b9ae 100644 --- a/src/AspNetCoreWithMarten/Samples/ConfiguringSessionCreation/Startup.cs +++ b/src/AspNetCoreWithMarten/Samples/ConfiguringSessionCreation/Startup.cs @@ -1,4 +1,6 @@ using System.Data; +using JasperFx; +using JasperFx.CodeGeneration; using Marten; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -58,13 +60,18 @@ public void ConfigureServices(IServiceCollection services) { opts.Connection(connectionString); }) - // Using the "Optimized artifact workflow" for Marten >= V5 - // sets up your Marten configuration based on your environment - // See https://martendb.io/configuration/optimized_artifact_workflow.html - .OptimizeArtifactWorkflow() + // Chained helper to replace the built in // session factory behavior .BuildSessionsWith(); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); #endregion } diff --git a/src/AspNetCoreWithMarten/Samples/EagerInitialization/Startup.cs b/src/AspNetCoreWithMarten/Samples/EagerInitialization/Startup.cs index 3778144e83..06415946ed 100644 --- a/src/AspNetCoreWithMarten/Samples/EagerInitialization/Startup.cs +++ b/src/AspNetCoreWithMarten/Samples/EagerInitialization/Startup.cs @@ -1,3 +1,5 @@ +using JasperFx; +using JasperFx.CodeGeneration; using Marten; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -22,13 +24,16 @@ public void ConfigureServices(IServiceCollection services) // By only the connection string services.AddMarten(connectionString) - // Using the "Optimized artifact workflow" for Marten >= V5 - // sets up your Marten configuration based on your environment - // See https://martendb.io/configuration/optimized_artifact_workflow.html - .OptimizeArtifactWorkflow() - // Spin up the DocumentStore right this second! .InitializeWith(); + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); + #endregion } diff --git a/src/AspNetCoreWithMarten/Samples/PerScopeSessionCreation/Startup.cs b/src/AspNetCoreWithMarten/Samples/PerScopeSessionCreation/Startup.cs index 7cf407afcd..c22282e992 100644 --- a/src/AspNetCoreWithMarten/Samples/PerScopeSessionCreation/Startup.cs +++ b/src/AspNetCoreWithMarten/Samples/PerScopeSessionCreation/Startup.cs @@ -1,5 +1,7 @@ using System; using System.Data; +using JasperFx; +using JasperFx.CodeGeneration; using Marten; using Marten.Services; using Microsoft.Extensions.Configuration; @@ -132,9 +134,15 @@ public void ConfigureServices(IServiceCollection services) // Using the "Optimized artifact workflow" for Marten >= V5 // sets up your Marten configuration based on your environment // See https://martendb.io/configuration/optimized_artifact_workflow.html - .OptimizeArtifactWorkflow() // Chained helper to replace the CustomSessionFactory .BuildSessionsWith(ServiceLifetime.Scoped); + + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); + #endregion } diff --git a/src/CoreTests/Examples/MultipleDocumentStores.cs b/src/CoreTests/Examples/MultipleDocumentStores.cs index f1f1227da1..e250bb33c3 100644 --- a/src/CoreTests/Examples/MultipleDocumentStores.cs +++ b/src/CoreTests/Examples/MultipleDocumentStores.cs @@ -1,5 +1,7 @@ using System.Threading; using System.Threading.Tasks; +using JasperFx; +using JasperFx.CodeGeneration; using JasperFx.Events.Daemon; using Marten; using Marten.Schema; @@ -35,11 +37,15 @@ public static async Task bootstrap() .AddAsyncDaemon(DaemonMode.HotCold) // Use IInitialData - .InitializeWith(new DefaultDataSet()) - - // Use the V5 optimized artifact workflow - // with the separate store as well - .OptimizeArtifactWorkflow(); + .InitializeWith(new DefaultDataSet()); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }).StartAsync(); #endregion diff --git a/src/CoreTests/using_optimized_artifact_workflow.cs b/src/CoreTests/reading_configuration_from_jasperfxoptions.cs similarity index 52% rename from src/CoreTests/using_optimized_artifact_workflow.cs rename to src/CoreTests/reading_configuration_from_jasperfxoptions.cs index 716df5d394..4301a0ac2f 100644 --- a/src/CoreTests/using_optimized_artifact_workflow.cs +++ b/src/CoreTests/reading_configuration_from_jasperfxoptions.cs @@ -4,6 +4,7 @@ using Lamar; using JasperFx.CodeGeneration; using JasperFx.Core.Reflection; +using JasperFx.MultiTenancy; using Marten; using Marten.Testing.Harness; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +15,7 @@ namespace CoreTests; -public class using_optimized_artifact_workflow +public class reading_configuration_from_jasperfxoptions { [Fact] public void all_the_defaults() @@ -37,6 +38,40 @@ public void all_the_defaults() } + [Fact] + public void can_override_tenancy_id_style() + { + using var container = Container.For(services => + { + services.AddMarten(opts => + { + opts.Connection(ConnectionSource.ConnectionString); + opts.TenantIdStyle = TenantIdStyle.ForceLowerCase; + }); + + services.CritterStackDefaults(x => x.TenantIdStyle = TenantIdStyle.ForceUpperCase); + }); + + container.GetInstance().As().Options.TenantIdStyle.ShouldBe(TenantIdStyle.ForceLowerCase); + } + + [Fact] + public void use_default_tenancy_id_style() + { + using var container = Container.For(services => + { + services.AddMarten(opts => + { + opts.Connection(ConnectionSource.ConnectionString); + // opts.TenantIdStyle = TenantIdStyle.ForceLowerCase; + }); + + services.CritterStackDefaults(x => x.TenantIdStyle = TenantIdStyle.ForceUpperCase); + }); + + container.GetInstance().As().Options.TenantIdStyle.ShouldBe(TenantIdStyle.ForceUpperCase); + } + public static async Task bootstrapping_example() { #region sample_using_optimized_artifact_workflow @@ -44,11 +79,15 @@ public static async Task bootstrapping_example() using var host = await Host.CreateDefaultBuilder() .ConfigureServices(services => { - services.AddMarten("connection string") - - // This feature opts into the new - // "Optimized artifact workflow" for Marten >= V5 - .OptimizeArtifactWorkflow(); + services.AddMarten("connection string"); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }).StartAsync(); #endregion @@ -61,13 +100,16 @@ public static async Task bootstrapping_example_with_static() using var host = await Host.CreateDefaultBuilder() .ConfigureServices(services => { - services.AddMarten("connection string") - - // This feature opts into the new - // "Optimized artifact workflow" for Marten >= V5 - .OptimizeArtifactWorkflow(TypeLoadMode.Static); + services.AddMarten("connection string"); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }).StartAsync(); - #endregion } @@ -77,7 +119,20 @@ public void using_optimized_mode_in_development() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(); + services.AddMarten(ConnectionSource.ConnectionString); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + + x.Development.GeneratedCodeMode = TypeLoadMode.Auto; + x.Development.ResourceAutoCreate = AutoCreate.CreateOrUpdate; + + x.TenantIdStyle = TenantIdStyle.ForceLowerCase; + }); }) .UseEnvironment("Development") .Start(); @@ -87,6 +142,8 @@ public void using_optimized_mode_in_development() var rules = store.Options.CreateGenerationRules(); + store.Options.TenantIdStyle.ShouldBe(TenantIdStyle.ForceLowerCase); + store.Options.AutoCreateSchemaObjects.ShouldBe(AutoCreate.CreateOrUpdate); store.Options.GeneratedCodeMode.ShouldBe(TypeLoadMode.Auto); @@ -100,7 +157,16 @@ public void using_optimized_mode_in_production() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(); + services.AddMarten(ConnectionSource.ConnectionString); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Auto; + x.Production.ResourceAutoCreate = AutoCreate.None; + x.Production.SourceCodeWritingEnabled = false; + }); }) .UseEnvironment("Production") .Start(); @@ -132,7 +198,16 @@ public void using_optimized_mode_in_production_override_type_load_mode() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(TypeLoadMode.Static); + services.AddMarten(ConnectionSource.ConnectionString); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + x.Production.SourceCodeWritingEnabled = false; + }); }) .UseEnvironment("Production") .Start(); @@ -155,7 +230,19 @@ public void using_optimized_mode_in_production_override_environment_name() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow("Local"); + services.AddMarten(ConnectionSource.ConnectionString); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.CreateOrUpdate; + + x.Development.GeneratedCodeMode = TypeLoadMode.Auto; + + x.DevelopmentEnvironmentName = "Local"; + }); }) .UseEnvironment("Local") .Start(); diff --git a/src/EventSourcingTests/Bugs/Bug_2865_configuration_assertion_with_flat_table_projections.cs b/src/EventSourcingTests/Bugs/Bug_2865_configuration_assertion_with_flat_table_projections.cs index 98add7eca0..d937c8933a 100644 --- a/src/EventSourcingTests/Bugs/Bug_2865_configuration_assertion_with_flat_table_projections.cs +++ b/src/EventSourcingTests/Bugs/Bug_2865_configuration_assertion_with_flat_table_projections.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; +using JasperFx; +using JasperFx.CodeGeneration; using JasperFx.Events.Daemon; using JasperFx.Events.Projections; using Marten; @@ -14,7 +16,7 @@ namespace EventSourcingTests.Bugs; public class Bug_2865_configuration_assertion_with_flat_table_projections { - [Fact] + //[Fact] -- this is flaky on CI. No earthly idea why public async Task should_be_able_to_assert_on_existence_of_flat_table_functions() { var appBuilder = Host.CreateApplicationBuilder(); @@ -33,9 +35,15 @@ public async Task should_be_able_to_assert_on_existence_of_flat_table_functions( // Add this .ApplyAllDatabaseChangesOnStartup() .UseLightweightSessions() - .OptimizeArtifactWorkflow() .AddAsyncDaemon(DaemonMode.Solo); + appBuilder.Services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + x.Production.SourceCodeWritingEnabled = false; + }); + var app = appBuilder.Build(); await app.StartAsync(); diff --git a/src/Marten/MartenServiceCollectionExtensions.cs b/src/Marten/MartenServiceCollectionExtensions.cs index eb97176df1..a98acd3dd7 100644 --- a/src/Marten/MartenServiceCollectionExtensions.cs +++ b/src/Marten/MartenServiceCollectionExtensions.cs @@ -440,54 +440,6 @@ public MartenStoreExpression(IServiceCollection services) public IServiceCollection Services { get; } - - /// - /// Adds the optimized artifact workflow to the store "T" - /// - /// - public MartenStoreExpression OptimizeArtifactWorkflow() - { - return OptimizeArtifactWorkflow(TypeLoadMode.Auto); - } - - - /// - /// Adds the optimized artifact workflow to the store "T" - /// - /// - /// - public MartenStoreExpression OptimizeArtifactWorkflow(string developmentEnvironment) - { - return OptimizeArtifactWorkflow(TypeLoadMode.Auto, developmentEnvironment); - } - - - /// - /// Adds the optimized artifact workflow to the store "T" - /// - /// - /// - public MartenStoreExpression OptimizeArtifactWorkflow(TypeLoadMode typeLoadMode) - { - Services.AddSingleton>(new OptimizedArtifactsWorkflow(typeLoadMode)); - return this; - } - - - /// - /// Adds the optimized artifact workflow to the store "T" - /// - /// - /// - /// - public MartenStoreExpression OptimizeArtifactWorkflow(TypeLoadMode typeLoadMode, - string developmentEnvironment) - { - Services.AddSingleton>( - new OptimizedArtifactsWorkflow(typeLoadMode, developmentEnvironment)); - return this; - } - /// /// Register the Async Daemon hosted service to continuously attempt to update asynchronous event projections /// @@ -780,61 +732,6 @@ public MartenConfigurationExpression UseNpgsqlDataSource( return this; } - - /// - /// Adds the optimized artifact workflow to this store. - /// See https://martendb.io/configuration/optimized_artifact_workflow.html for more information. - /// - /// - public MartenConfigurationExpression OptimizeArtifactWorkflow() - { - return OptimizeArtifactWorkflow(TypeLoadMode.Auto); - } - - /// - /// Adds the optimized artifact workflow to this store with ability to override the TypeLoadMode in "Production" mode. - /// See https://martendb.io/configuration/optimized_artifact_workflow.html for more information. - /// - /// - /// - [Obsolete(StoreOptions.PreferJasperFxMessage)] - public MartenConfigurationExpression OptimizeArtifactWorkflow(TypeLoadMode typeLoadMode) - { - var configure = new OptimizedArtifactsWorkflow(typeLoadMode); - Services.AddSingleton(configure); - - return this; - } - - /// - /// Adds the optimized artifact workflow to this store. - /// See https://martendb.io/configuration/optimized_artifact_workflow.html for more information. - /// - /// - /// - [Obsolete(StoreOptions.PreferJasperFxMessage)] - public MartenConfigurationExpression OptimizeArtifactWorkflow(string developmentEnvironment) - { - return OptimizeArtifactWorkflow(TypeLoadMode.Auto, developmentEnvironment); - } - - /// - /// Adds the optimized artifact workflow to this store with ability to override the TypeLoadMode in "Production" mode. - /// See https://martendb.io/configuration/optimized_artifact_workflow.html for more information. - /// - /// - /// - /// - [Obsolete(StoreOptions.PreferJasperFxMessage)] - public MartenConfigurationExpression OptimizeArtifactWorkflow(TypeLoadMode typeLoadMode, - string developmentEnvironment) - { - var configure = new OptimizedArtifactsWorkflow(typeLoadMode, developmentEnvironment); - Services.AddSingleton(configure); - - return this; - } - /// /// Adds initial data sets to the Marten store and ensures that they will be /// executed upon IHost initialization @@ -1031,42 +928,6 @@ public LambdaConfigureMarten(Action configure): } } -[Obsolete(StoreOptions.PreferJasperFxMessage)] -internal class OptimizedArtifactsWorkflow: IConfigureMarten -{ - private readonly string _developmentEnvironment = "Development"; - private readonly TypeLoadMode _productionMode; - - public OptimizedArtifactsWorkflow(TypeLoadMode productionMode) - { - _productionMode = productionMode; - } - - public OptimizedArtifactsWorkflow(TypeLoadMode productionMode, string developmentEnvironment): this(productionMode) - { - _developmentEnvironment = developmentEnvironment; - } - - public void Configure(IServiceProvider services, StoreOptions options) - { - var environment = services.GetRequiredService(); - - if (environment.IsEnvironment(_developmentEnvironment)) - { - options.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; - options.GeneratedCodeMode = TypeLoadMode.Auto; - } - else - { - options.AutoCreateSchemaObjects = AutoCreate.None; - options.GeneratedCodeMode = _productionMode; - - - options.SourceCodeWritingEnabled = false; - } - } -} - internal interface IDocumentStoreSource { IDocumentStore Resolve(IServiceProvider serviceProvider); @@ -1079,16 +940,3 @@ public IDocumentStore Resolve(IServiceProvider services) return services.GetRequiredService(); } } - -internal class OptimizedArtifactsWorkflow: OptimizedArtifactsWorkflow, IConfigureMarten - where T : IDocumentStore -{ - public OptimizedArtifactsWorkflow(TypeLoadMode productionMode): base(productionMode) - { - } - - public OptimizedArtifactsWorkflow(TypeLoadMode productionMode, string developmentEnvironment): base(productionMode, - developmentEnvironment) - { - } -} diff --git a/src/Marten/StoreOptions.GeneratesCode.cs b/src/Marten/StoreOptions.GeneratesCode.cs index 60edd12e3a..d8a0194398 100644 --- a/src/Marten/StoreOptions.GeneratesCode.cs +++ b/src/Marten/StoreOptions.GeneratesCode.cs @@ -88,6 +88,11 @@ internal void ReadJasperFxOptions(JasperFxOptions? options) { if (options == null) return; + if (!_tenantIdStyle.HasValue) + { + _tenantIdStyle = options.TenantIdStyle; + } + ApplicationAssembly ??= options.ApplicationAssembly; GeneratedCodeOutputPath ??= options.GeneratedCodeOutputPath; _generatedCodeMode ??= options.ActiveProfile.GeneratedCodeMode; diff --git a/src/Marten/StoreOptions.cs b/src/Marten/StoreOptions.cs index 4dc13be19d..1dfcecc76c 100644 --- a/src/Marten/StoreOptions.cs +++ b/src/Marten/StoreOptions.cs @@ -81,7 +81,11 @@ internal INpgsqlDataSourceFactory NpgsqlDataSourceFactory /// /// Configure tenant id behavior within this Marten DocumentStore /// - public TenantIdStyle TenantIdStyle { get; set; } = TenantIdStyle.CaseSensitive; + public TenantIdStyle TenantIdStyle + { + get => _tenantIdStyle.HasValue ? _tenantIdStyle.Value : TenantIdStyle.CaseSensitive; + set => _tenantIdStyle = value; + } /// /// Add, remove, or reorder global session listeners @@ -409,6 +413,7 @@ public ITenancy Tenancy private readonly EventGraph _eventGraph; private readonly LinqParsing _linq; private int _updateBatchSize = 500; + private TenantIdStyle? _tenantIdStyle; IReadOnlyEventStoreOptions IReadOnlyStoreOptions.Events => EventGraph; diff --git a/src/StressTests/using_multiple_document_stores_in_same_host.cs b/src/StressTests/using_multiple_document_stores_in_same_host.cs index bd1be9bae7..80e9983369 100644 --- a/src/StressTests/using_multiple_document_stores_in_same_host.cs +++ b/src/StressTests/using_multiple_document_stores_in_same_host.cs @@ -181,14 +181,22 @@ public void using_optimized_mode_in_development() { opts.Connection(ConnectionSource.ConnectionString); opts.SetApplicationProject(GetType().Assembly); - }).OptimizeArtifactWorkflow(); + }); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); services.AddMartenStore(opts => { opts.Connection(ConnectionSource.ConnectionString); opts.DatabaseSchemaName = "first_store"; opts.SetApplicationProject(GetType().Assembly); - }).OptimizeArtifactWorkflow(); + }); }) @@ -214,14 +222,22 @@ public void using_optimized_mode_in_production() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(); + services.AddMarten(ConnectionSource.ConnectionString); services.AddMartenStore(opts => { opts.Connection(ConnectionSource.ConnectionString); opts.DatabaseSchemaName = "first_store"; opts.SetApplicationProject(GetType().Assembly); - }).OptimizeArtifactWorkflow(); + }); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }) .UseEnvironment("Production") .Start(); @@ -279,14 +295,22 @@ public void using_optimized_mode_in_production_override_type_load_mode() }); - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(TypeLoadMode.Static); + services.AddMarten(ConnectionSource.ConnectionString); services.AddMartenStore(opts => { opts.Connection(ConnectionSource.ConnectionString); opts.DatabaseSchemaName = "first_store"; opts.SetApplicationProject(typeof(IFirstStore).Assembly); - }).OptimizeArtifactWorkflow(TypeLoadMode.Static); + }); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }) .Start(); @@ -310,7 +334,7 @@ public void use_secondary_options_configure_against_additional_store() using var host = new HostBuilder() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(TypeLoadMode.Static); + services.AddMarten(ConnectionSource.ConnectionString); services.AddMartenStore(opts => { @@ -323,6 +347,14 @@ public void use_secondary_options_configure_against_additional_store() { opts.AutoCreateSchemaObjects = AutoCreate.None; }); + + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); }) .Start(); @@ -339,7 +371,7 @@ public void bootstrap_async_daemon_for_secondary_store() .ConfigureServices(services => { - services.AddMarten(ConnectionSource.ConnectionString).OptimizeArtifactWorkflow(TypeLoadMode.Static); + services.AddMarten(ConnectionSource.ConnectionString); services.AddMartenStore(opts => { @@ -347,6 +379,14 @@ public void bootstrap_async_daemon_for_secondary_store() opts.DatabaseSchemaName = "first_store"; }).AddAsyncDaemon(DaemonMode.HotCold); + // In a "Production" environment, we're turning off the + // automatic database migrations and dynamic code generation + services.CritterStackDefaults(x => + { + x.Production.GeneratedCodeMode = TypeLoadMode.Static; + x.Production.ResourceAutoCreate = AutoCreate.None; + }); + }) .Start();