Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use RavenDB
dotnet add package RavenDB.Client
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
You can’t perform that action at this time.