MongoQ.AspNetCore 0.1.32-alpha

This is a prerelease version of MongoQ.AspNetCore.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoQ.AspNetCore --version 0.1.32-alpha                
NuGet\Install-Package MongoQ.AspNetCore -Version 0.1.32-alpha                
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="MongoQ.AspNetCore" Version="0.1.32-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoQ.AspNetCore --version 0.1.32-alpha                
#r "nuget: MongoQ.AspNetCore, 0.1.32-alpha"                
#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 MongoQ.AspNetCore as a Cake Addin
#addin nuget:?package=MongoQ.AspNetCore&version=0.1.32-alpha&prerelease

// Install MongoQ.AspNetCore as a Cake Tool
#tool nuget:?package=MongoQ.AspNetCore&version=0.1.32-alpha&prerelease                

MongoQ

The Q stands for quick

Quickly add the MongoDB C# Driver to a dotnet project with some helpful additions to get started quicker.

Usage:

Creating a repository is very easy with MongoQ. MongoQ will setup your collection for you in a standard, repeatable way so you can focus on your repository code.

using MongoQ;
    
public class MyRepo : MongoQRepo<MyEntity>
{
    public MyRepo() : base("collectionName") { }

    public MyEntity FindOne(ObjectId id)
    {
        return _collection
            .Find(e => e.Id == id)
            .FirstOrDefault();
    }
}

Getting started

Installation

Add the Nuget Package.

For ASP.NET:

Install-Package MongoQ.AspNetCore

Generic C#:

Install-Package MongoQ

First, Configure your mongo database

See below, configuration is different per-environment to conform to conventions of your framework.

Create a Repo

Inherit your repository from MongoQRepo<T> where T is the class of your entity.

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System.Threading.Tasks;
    
public class MyEntity
{
    [BsonId]
    public ObjectId Id { get; set; }
}
public class MyRepo : MongoQ.MongoQRepo<MyEntity>
{
    public MyRepo() : base("collectionName") { }

    public async Task<MyEntity> FindOne(ObjectId id)
    {
        return await _collection
            .Find(e => e.Id == id)
            .FirstOrDefaultAsync();
    }
}

Configuration

AspnetCore Configuration

In your Startup.cs setup mongo in the Startup.Configure method using the IApplicationBuilder app parameter:

Set Database Name:

app.MongoQSetDbName("MyDatabase");

Set Connection string:

app.MongoQSetConnString(config.GetConnectionString("myConnString"));

Customize the cluster:

app.MongoQConfigureCluster(options =>
{
    // configure the connection pool
    options.ConfigureConnectionPool(
        (c) => new ConnectionPoolSettings(
            c.MaintenanceInterval,
            c.MaxConnections,
            c.MinConnections,
            c.WaitQueueSize,
            c.WaitQueueTimeout
        ));

    // subscribe to command failed events
    options.Subscribe<MongoDB.Driver.Core.Events.CommandFailedEvent>(e =>
    {
        System.Diagnostics.Debug.WriteLine($"Mongo Event:{e.GetType().Name}");
        System.Diagnostics.Debug.WriteLine($"CMD COMMAND FAILED:{e.CommandName}");
        System.Diagnostics.Debug.WriteLine($"CMD Exception:{e.Failure}");
    });
    // see generated commands in output
    options.Subscribe<MongoDB.Driver.Core.Events.CommandStartedEvent>(e =>
    {
        System.Diagnostics.Debug.WriteLine($"Mongo Event:{e.GetType().Name}");
        System.Diagnostics.Debug.WriteLine("CMD Start:" + e.Command?.ToJson());
        System.Diagnostics.Debug.WriteLine("CMD Name:" + e.CommandName);
    });
});

Customize default database settings:

app.MongoQConfigureDbSettings(options =>
{
    options.ReadPreference = ReadPreference.Nearest;
    options.WriteConcern = WriteConcern.WMajority;
    options.ReadConcern = ReadConcern.Majority;
});
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.35-alpha 172 5/10/2022
0.1.34-alpha 182 5/10/2022
0.1.33 496 3/13/2022 0.1.33 is deprecated because it is no longer maintained.
0.1.33-alpha 166 3/13/2022
0.1.32 456 2/12/2022
0.1.32-alpha 154 2/12/2022
0.1.31-alpha 173 2/12/2022
0.1.29-alpha 176 1/30/2022
0.1.28-alpha 180 1/29/2022
0.1.26-alpha 191 12/7/2021
0.1.25-alpha 262 10/12/2021
0.1.24-alpha 249 8/20/2021
0.1.23-alpha 218 8/19/2021
0.1.14 306 8/16/2021
0.1.1 320 8/16/2021
0.0.1 303 8/14/2021

Changed build to run .NET Standard 2.0 so it has greater compatibility.