VersaTul.Data.MongoDB
1.0.25
Prefix Reserved
See the version list below for details.
dotnet add package VersaTul.Data.MongoDB --version 1.0.25
NuGet\Install-Package VersaTul.Data.MongoDB -Version 1.0.25
<PackageReference Include="VersaTul.Data.MongoDB" Version="1.0.25" />
paket add VersaTul.Data.MongoDB --version 1.0.25
#r "nuget: VersaTul.Data.MongoDB, 1.0.25"
// Install VersaTul.Data.MongoDB as a Cake Addin #addin nuget:?package=VersaTul.Data.MongoDB&version=1.0.25 // Install VersaTul.Data.MongoDB as a Cake Tool #tool nuget:?package=VersaTul.Data.MongoDB&version=1.0.25
VersaTul Data MongoDB
VersaTul Data MongoDB is a C# library that provides functionality for working with Mongo Databases. The library uses the repository design pattern to provide the functionality to Fetch, Add, Update, or Delete data.
Features
- Generic interface for supporting common CRUD operations
- Generic interface for fetching configuration settings
- Generic interface for creating BsonClassMaps for entities
- Default implementation of the data configuration interface
- Abstract class providing common functionality for a MongoDB Database
- Default implementation of the entity map interface
- Helper class for generating search conditional expressions
- Abstract entity used for all Business Entities
Installation
You can install the library from NuGet using the following command:
dotnet add package VersaTul.Data.MongoDB
Usage
To use VersaTul Data MongoDB, you need to do the following steps:
- Create your entity classes by inheriting from the Entity abstract class
- Create your entity maps by inheriting from the BaseMap<TEntity> class and implementing the IEntityMap<TEntity> interface
- Create your repository classes by inheriting from the BaseRepository<TEntity, TMap, TKey> class and implementing the IRepository<TEntity, TKey> interface
- Configure your container using AutoFac Module and register your configurations, repositories, and entity maps
- Inject your repositories into your controllers or services and use the methods provided by the IRepository<TEntity, TKey> interface
For example, to create a repository for a Car entity, you can do the following:
// Car entity class
public class Car : Entity<string>
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
}
// Car entity map class
public class CarMap : BaseMap<Car>
{
public override void Configure()
{
BsonClassMap.RegisterClassMap<Car>(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id);
cm.SetIgnoreExtraElements(true);
});
}
}
// Car repository class
public class CarRepository : BaseRepository<Car, CarMap, string>, ICarRepository
{
public CarRepository(IDataConfiguration<string> dataConfiguration) : base(dataConfiguration)
{
}
}
// Car repository interface
public interface ICarRepository : IRepository<Car, string>
{
}
// Configure the container using AutoFac Module
public class AppModule : Module
{
protected override void Load(ContainerBuilder builder)
{
//Configs
var configSettings = new Builder()
.AddOrReplace("MongoDb", "mongodb://root:password123@localhost:27017/DemoDB")
.BuildConfig();
builder.RegisterInstance(configSettings);
//Singletons
builder.RegisterGeneric(typeof(DataConfiguration<>)).As(typeof(IDataConfiguration<>)).SingleInstance();
builder.RegisterType<CarRepository>().As<ICarRepository>().SingleInstance();
builder.RegisterType<CarMap>().As<IEntityMap<Car>>().SingleInstance();
//Per Dependency
}
}
// Repository usage in a controller
[Route("api/cars")]
public class CarController : Controller
{
private readonly ICarRepository carRepository;
public CarController(ICarRepository carRepository)
{
this.carRepository = carRepository;
}
// Get
[HttpGet]
public IActionResult GetCars()
{
var cars = carRepository.ToList();
return OK(cars);
}
}
Documentation
For more information on how to use VersaTul Data MongoDB, please refer to the official documentation.
License
VersaTul Data MongoDB is licensed under the MIT License.
Product | Versions 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. |
-
net8.0
- LinqKit.Microsoft.EntityFrameworkCore (>= 8.1.5)
- MongoDB.Bson (>= 2.25.0)
- MongoDB.Driver (>= 2.25.0)
- MongoDB.Driver.Core (>= 2.25.0)
- VersaTul.Configurations (>= 1.0.15)
- VersaTul.Contracts (>= 1.0.8)
- VersaTul.Extensions (>= 1.0.12)
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.26 | 84 | 10/12/2024 |
1.0.25 | 93 | 10/5/2024 |
1.0.24 | 119 | 4/5/2024 |
1.0.23 | 111 | 4/4/2024 |
1.0.22 | 104 | 4/4/2024 |
1.0.21 | 125 | 3/1/2024 |
1.0.20 | 113 | 2/2/2024 |
1.0.19 | 93 | 2/1/2024 |
1.0.18 | 129 | 1/20/2024 |
1.0.17 | 113 | 1/15/2024 |
1.0.16 | 95 | 1/14/2024 |
1.0.15 | 105 | 1/13/2024 |
1.0.14 | 113 | 1/11/2024 |
1.0.13 | 176 | 11/4/2023 |
1.0.12 | 120 | 10/12/2023 |
1.0.11 | 161 | 7/22/2023 |