Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Created November 11, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/0007f89c6bd63856a34e475bbf618d86 to your computer and use it in GitHub Desktop.
Save gistlyn/0007f89c6bd63856a34e475bbf618d86 to your computer and use it in GitHub Desktop.
Use Marten
dotnet add package RavenDB.Client
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Marten;
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
namespace MyApp
{
public class ConfigureDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
var store = DocumentStore.For(opts => {
opts.Connection(context.Configuration.GetConnectionString("Marten")
?? "host=localhost;username=test;password=test;database=marten");
Options.ForEach(fn => fn(opts));
});
store.Advanced.Clean.CompletelyRemoveAll();
services.AddSingleton<IDocumentStore>(store);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment