Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active September 19, 2020 13:27
Show Gist options
  • Save gistlyn/efcf39f4ce37a4822571a3a3433f5b4a to your computer and use it in GitHub Desktop.
Save gistlyn/efcf39f4ce37a4822571a3a3433f5b4a to your computer and use it in GitHub Desktop.
Use Marten
dotnet add package Marten
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using Marten;
namespace MyApp
{
public class ConfigureMarten : IConfigureServices
{
public static List<Action<StoreOptions>> Options { get; } = new List<Action<StoreOptions>>();
IConfiguration Configuration { get; }
public ConfigureDb(IConfiguration configuration) => Configuration = configuration;
public void Configure(IServiceCollection services)
{
var store = DocumentStore.For(opts =>
{
opts.Connection(Configuration.GetConnectionString("Marten")
?? "host=localhost;username=test;password=test;database=marten");
Options.ForEach(fn => fn(opts));
});
store.Advanced.Clean.CompletelyRemoveAll();
services.AddSingleton<IDocumentStore>(store);
}
}
}
@gistlyn
Copy link
Author

gistlyn commented Sep 19, 2020

@Lippur Updated thx 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment