Mongo-Repo
1.0.3
dotnet add package Mongo-Repo --version 1.0.3
NuGet\Install-Package Mongo-Repo -Version 1.0.3
<PackageReference Include="Mongo-Repo" Version="1.0.3" />
<PackageVersion Include="Mongo-Repo" Version="1.0.3" />
<PackageReference Include="Mongo-Repo" />
paket add Mongo-Repo --version 1.0.3
#r "nuget: Mongo-Repo, 1.0.3"
#addin nuget:?package=Mongo-Repo&version=1.0.3
#tool nuget:?package=Mongo-Repo&version=1.0.3
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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- MongoDB.Driver (>= 2.17.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.