Last active
June 22, 2019 21:16
-
-
Save gistlyn/8ef41d53c8f54d85a50f26e2aad6da73 to your computer and use it in GitHub Desktop.
Use RavenDB
This file contains hidden or 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 RavenDB.Client |
This file contains hidden or 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 Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using ServiceStack; | |
using ServiceStack.DataAnnotations; | |
using Raven.Client.Documents; | |
namespace MyApp | |
{ | |
public class ConfigureRavenDb : IConfigureServices | |
{ | |
IConfiguration Configuration { get; } | |
public ConfigureRavenDb(IConfiguration configuration) => Configuration = configuration; | |
public void Configure(IServiceCollection services) | |
{ | |
var store = new DocumentStore | |
{ | |
Urls = new[] // URL to the Server, or list of URLs to all Cluster Servers (Nodes) | |
{ | |
Configuration.GetConnectionString("RavenDB") ?? "http://localhost:8080" | |
}, | |
Database = "MyApp", // Default database that DocumentStore will interact with | |
Conventions = { } // DocumentStore customizations | |
}; | |
store.Conventions.FindIdentityProperty = p => { | |
var attr = p.DeclaringType.FirstAttribute<IndexAttribute>(); // Allow overriding 'Id' Identity property | |
return attr != null | |
? p.Name == attr.Name | |
: p.Name == "Id"; | |
}; | |
services.AddSingleton<IDocumentStore>(store.Initialize()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment