Defra.Livestock.Sdk.Storage.Mongo 0.1.0-LREG-999-alpha.4.1

Prefix Reserved
This is a prerelease version of Defra.Livestock.Sdk.Storage.Mongo.
dotnet add package Defra.Livestock.Sdk.Storage.Mongo --version 0.1.0-LREG-999-alpha.4.1
                    
NuGet\Install-Package Defra.Livestock.Sdk.Storage.Mongo -Version 0.1.0-LREG-999-alpha.4.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="Defra.Livestock.Sdk.Storage.Mongo" Version="0.1.0-LREG-999-alpha.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Defra.Livestock.Sdk.Storage.Mongo" Version="0.1.0-LREG-999-alpha.4.1" />
                    
Directory.Packages.props
<PackageReference Include="Defra.Livestock.Sdk.Storage.Mongo" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Defra.Livestock.Sdk.Storage.Mongo --version 0.1.0-LREG-999-alpha.4.1
                    
#r "nuget: Defra.Livestock.Sdk.Storage.Mongo, 0.1.0-LREG-999-alpha.4.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.
#:package Defra.Livestock.Sdk.Storage.Mongo@0.1.0-LREG-999-alpha.4.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Defra.Livestock.Sdk.Storage.Mongo&version=0.1.0-LREG-999-alpha.4.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Defra.Livestock.Sdk.Storage.Mongo&version=0.1.0-LREG-999-alpha.4.1&prerelease
                    
Install as a Cake Tool

Defra.Livestock.Sdk.Storage.Mongo

MongoDB set-up for Livestock Information Service (LIS) .NET services: a client factory for the configured database, camel-case BSON conventions, and AWS IAM authentication support.

Part of lis-sdk-nuget-storage.

Installation

dotnet add package Defra.Livestock.Sdk.Storage.Mongo

This package does not depend on the other storage packages. It targets net10.0.

Usage

using Defra.Livestock.Sdk.Storage.Mongo;

builder.Services.AddMongoDatabase(builder.Configuration);

AddMongoDatabase reads the Mongo section described under Configuration and:

  • registers camel-case element names for all BSON-serialised types
  • registers the MongoDB driver's AWS authentication extension
  • binds and validates the settings, checked at start-up
  • registers IMongoDbClientFactory as a singleton, which owns one MongoClient and disposes it when the container is disposed
public class AnimalRepository(IMongoDbClientFactory factory)
{
    private readonly IMongoCollection<Animal> animals = factory.GetCollection<Animal>("animals");

    public Task<Animal?> FindAsync(Guid id) =>
        animals.Find(a => a.Id == id).FirstOrDefaultAsync();
}

Creating the factory does not connect to the server. The driver connects on first use.

Configuration

{
  "Mongo": {
    "DatabaseUri": "mongodb://localhost:27017",
    "DatabaseName": "my-db"
  }
}
Key Default Meaning
Mongo:DatabaseUri none (required) MongoDB connection string
Mongo:DatabaseName none (required) Database that GetDatabase and GetCollection use

If either is missing, start-up fails with OptionsValidationException. To use AWS IAM authentication, put authMechanism=MONGODB-AWS in the connection string. The driver then takes credentials from the default AWS credentials chain.

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-LREG-999-alpha.4.1 58 11/26/2026