Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/AspNetCoreWithMarten/Samples/ByNestedClosure/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using JasperFx;
using JasperFx.CodeGeneration;
using Marten;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 9 additions & 6 deletions src/AspNetCoreWithMarten/Samples/ByStoreOptions/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using JasperFx;
using JasperFx.CodeGeneration;
using Marten;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Data;
using JasperFx;
using JasperFx.CodeGeneration;
using Marten;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -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<CustomSessionFactory>();

// 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
}

Expand Down
15 changes: 10 additions & 5 deletions src/AspNetCoreWithMarten/Samples/EagerInitialization/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using JasperFx;
using JasperFx.CodeGeneration;
using Marten;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Data;
using JasperFx;
using JasperFx.CodeGeneration;
using Marten;
using Marten.Services;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -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<ScopedSessionFactory>(ServiceLifetime.Scoped);

services.CritterStackDefaults(x =>
{
x.Production.GeneratedCodeMode = TypeLoadMode.Static;
x.Production.ResourceAutoCreate = AutoCreate.None;
});

#endregion
}

Expand Down
16 changes: 11 additions & 5 deletions src/CoreTests/Examples/MultipleDocumentStores.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@

namespace CoreTests;

public class using_optimized_artifact_workflow
public class reading_configuration_from_jasperfxoptions
{
[Fact]
public void all_the_defaults()
Expand All @@ -37,18 +38,56 @@ 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<IDocumentStore>().As<DocumentStore>().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<IDocumentStore>().As<DocumentStore>().Options.TenantIdStyle.ShouldBe(TenantIdStyle.ForceUpperCase);
}

public static async Task bootstrapping_example()
{
#region sample_using_optimized_artifact_workflow

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
Expand All @@ -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
}

Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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();

Expand Down
Loading
Loading