Skip to content

RavenDB store

Olivier Lefebvre edited this page Feb 12, 2021 · 4 revisions

To use the RavenDb store instead of EntityFramework:

  • add a package reference to Aguacongas.AspNetCore.Authentication.RavenDb in your project.
  • use one of AddRavenDbStore extension method to setup your repository.

By registring a document store in DI

// Add authentication
var authBuilder = services
    .AddAuthentication();

// Add the magic
var dynamicBuilder = authBuilder
    .AddDynamic<SchemeDefinition>()
    .AddRavenDbStore();

// Add the ravendb document store
service.AddSingleton(p => new DocumentStore()
{
    // Define the cluster node URLs (required)
    Urls = new[] { "http://your_RavenDB_cluster_node", 
                    /*some additional nodes of this cluster*/ },

    // Define a client certificate (optional)
    Certificate = new X509Certificate2("C:\\path_to_your_pfx_file\\cert.pfx"),
    Database = "SchemeDefinition"

// Initialize the Document Store
}.Initialize());

By providing the get document store function

// Add authentication
var authBuilder = services
    .AddAuthentication();

// Add the magic
var dynamicBuilder = authBuilder
    .AddDynamic<SchemeDefinition>()
    .AddRavenDbStore(p => new DocumentStore()
    {
        // Define the cluster node URLs (required)
        Urls = new[] { "http://your_RavenDB_cluster_node", 
                        /*some additional nodes of this cluster*/ },

        // Define a client certificate (optional)
        Certificate = new X509Certificate2("C:\\path_to_your_pfx_file\\cert.pfx"),
        Database = "SchemeDefinition"

    // Initialize the Document Store
    }.Initialize());