Last active
September 19, 2020 13:27
-
-
Save gistlyn/efcf39f4ce37a4822571a3a3433f5b4a to your computer and use it in GitHub Desktop.
Use Marten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package Marten |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
@Lippur updated now, thx!
Another thing, line 23 throws an error because of the way the Options property is typed. The list on line 11 should probably be typed as List<Action<StoreOptions>>
instead.
@Lippur Updated thx 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The package installed here should be
Marten
instead ofRavenDB.Client
.