RavenDB.DependencyInjection 5.0.1

dotnet add package RavenDB.DependencyInjection --version 5.0.1                
NuGet\Install-Package RavenDB.DependencyInjection -Version 5.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RavenDB.DependencyInjection" Version="5.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RavenDB.DependencyInjection --version 5.0.1                
#r "nuget: RavenDB.DependencyInjection, 5.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RavenDB.DependencyInjection as a Cake Addin
#addin nuget:?package=RavenDB.DependencyInjection&version=5.0.1

// Install RavenDB.DependencyInjection as a Cake Tool
#tool nuget:?package=RavenDB.DependencyInjection&version=5.0.1                

RavenDB.DependencyInjection

Dependency Injection package for using RavenDB with ASP.NET Core.

This package lets you configure a RavenDB DocumentStore and create a singleton for it in the dependency injection container. Additionally, you can configure an IAsyncDocumentSession (or its synchronous equivalent) to be created per scope.

Getting Started

Install the RavenDB.DependencyInjection library through NuGet.

Install-Package RavenDB.DependencyInjection

Usage

Add a RavenSettings section to your appsettings.json:

"RavenSettings": {
    "Urls": [
       "http://live-test.ravendb.net"
    ],
    "DatabaseName": "Demo",
    "CertFilePath": "",
    "CertPassword": ""
},

Note that CertFilePath and CertPassword are optional. If you use a certificate to connect to your database, this should be a path relative to the content root. Is your certificate stored outside your code? See manual configuration.

Then in Startup.cs, tell Raven to use this database and add it to the DI container:

public void ConfigureServices(IServiceCollection services)
{
    // 1. Add an IDocumentStore singleton. Make sure that RavenSettings section exist in appsettings.json
    services.AddRavenDbDocStore();

    // 2. Add a scoped IAsyncDocumentSession. For the sync version, use .AddRavenSession().
    services.AddRavenDbAsyncSession(); 
}

Now you're cooking! Your controllers and services can now have IDocumentStore, IAsyncDocumentSession, or IDocumentSession injected into them. 😎

Configuring Raven conventions

Do you need to configure RavenDB conventions or perform other work before docStore.Initialize()? It's simple:

services.AddRavenDbDocStore(options => 
{
    options.BeforeInitializeDocStore = docStore => docStore.Conventions.IdentityPartsSeparator = "-";
}

Manual configuration

Is your Raven information stored outside of your code, such as environment variables or Azure Key Vault? If so, you can configure your doc store like this:

services.AddRavenDbDocStore(options =>
{
    // Grab the DB name from appsettings.json
    var dbName = options.Settings.DbName;
    
    // But grab the cert and password from the cloud
    var certBytes = Convert.FromBase64String(...); // load the certificate from wherever
    var certPassword = ...; // grab the password from wherever
    options.Certificate = new X509Certificate2(certBytes, certPassword);
});

View the Sample project to see it all in action.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on RavenDB.DependencyInjection:

Package Downloads
RavenDB.Identity

The simple and easy RavenDB Identity provider for ASP.NET Core. Use Raven to store your users and logins with just a few lines of code.

Dafitech.Common.Library

Common library has functions and methods that attends to requirements and programming style on Dafitech projects.

Dafitech.Common.GlobalDomain

Dafitech common global domain classes and DTOs

Dafitech.Common.DataAccess

Dafitech database access classes and methods.

BccPay.Core.DataAccess

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RavenDB.DependencyInjection:

Repository Stars
JasperFx/wolverine
Supercharged .NET server side development!
Version Downloads Last updated
5.0.1 26,078 1/12/2024
5.0.0 333 1/12/2024
4.0.2 176,855 4/1/2021
4.0.1 839 3/30/2021
4.0.0 15,503 7/24/2020
3.1.0 11,396 11/13/2019
3.0.0 9,059 4/5/2019
2.0.3 7,113 3/11/2019
2.0.2 1,151 2/28/2019
2.0.1 1,870 2/28/2019
2.0.0 1,123 2/28/2019
1.0.0 2,055 6/28/2016
1.0.0-rc2 1,559 6/27/2016

.NET 8 and Raven 6.