Mongo-Repo 1.0.3

dotnet add package Mongo-Repo --version 1.0.3
                    
NuGet\Install-Package Mongo-Repo -Version 1.0.3
                    
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="Mongo-Repo" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mongo-Repo" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Mongo-Repo" />
                    
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 Mongo-Repo --version 1.0.3
                    
#r "nuget: Mongo-Repo, 1.0.3"
                    
#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.
#addin nuget:?package=Mongo-Repo&version=1.0.3
                    
Install Mongo-Repo as a Cake Addin
#tool nuget:?package=Mongo-Repo&version=1.0.3
                    
Install Mongo-Repo as a Cake Tool

Mongo-Repo (.Net6)

Add the latest NuGet package of Mongo-Repo. After that in your project, you need to add the MongoDb configuration in your appsettings.json file. i.e.

"MongoDbSettings": {
    "ConnectionString": "your-mongodb-connection-string-here",
    "DatabaseName": "your-mongodb-database-name-here"
  },

After adding it to your appsettings.json file. You should add these two provided below lines in your program.cs file of .Net6 app.

Code for Program.cs

// Adding Mongo-Repo services to the container 
builder.Services.Configure<AcquireMongoClient>(builder.Configuration.GetSection("MongoDbSettings"));
builder.Services.AddMongoRepoServices();

MongoDB Entity

Note: Your MongoDB Entity class must need to inherit Document abstract class of Mongo-Repo.

Example
[BsonCollection("people")]
public class Person : Document
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
}

You can also specify your collection name with BsonCollection Attribute.

After that you can inject the main Generic Repository Class of this NuGet package which is IMongoRepository.

Usage Example

public class WeatherForecastController : ControllerBase
{
    private static readonly string[] Summaries = new[]
    {
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

    private readonly ILogger<WeatherForecastController> _logger;
    private readonly IMongoRepository<Person> _peopleRepository;

    public WeatherForecastController(ILogger<WeatherForecastController> logger, IMongoRepository<Person> peopleRepository)
    {
        _logger = logger;
        _peopleRepository = peopleRepository;
    }
    [HttpPost("registerPerson")]
    public async Task AddPerson(string firstName, string lastName)
    {
        var person = new Person()
        {
            FirstName = "John",
            LastName = "Doe"
        };

        await _peopleRepository.InsertOneAsync(person);
    }  
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.0.3 459 7/28/2022
1.0.2 413 7/28/2022
1.0.1 497 7/25/2022
1.0.0 453 7/25/2022