VersaTul.Data.MongoDB
1.0.27
Prefix Reserved
dotnet add package VersaTul.Data.MongoDB --version 1.0.27
NuGet\Install-Package VersaTul.Data.MongoDB -Version 1.0.27
<PackageReference Include="VersaTul.Data.MongoDB" Version="1.0.27" />
paket add VersaTul.Data.MongoDB --version 1.0.27
#r "nuget: VersaTul.Data.MongoDB, 1.0.27"
// Install VersaTul.Data.MongoDB as a Cake Addin #addin nuget:?package=VersaTul.Data.MongoDB&version=1.0.27 // Install VersaTul.Data.MongoDB as a Cake Tool #tool nuget:?package=VersaTul.Data.MongoDB&version=1.0.27
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. net9.0 is compatible. |
-
net8.0
- LinqKit.Microsoft.EntityFrameworkCore (>= 8.1.5)
- MongoDB.Bson (>= 3.1.0)
- MongoDB.Driver (>= 3.1.0)
- VersaTul.Configurations (>= 1.0.16)
- VersaTul.Contracts (>= 1.0.10)
- VersaTul.Extensions (>= 1.0.15)
-
net9.0
- LinqKit.Microsoft.EntityFrameworkCore (>= 9.0.7)
- MongoDB.Bson (>= 3.1.0)
- MongoDB.Driver (>= 3.1.0)
- VersaTul.Configurations (>= 1.0.16)
- VersaTul.Contracts (>= 1.0.10)
- VersaTul.Extensions (>= 1.0.15)
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.27 | 71 | 12/10/2024 |
1.0.26 | 89 | 10/12/2024 |
1.0.25 | 99 | 10/5/2024 |
1.0.24 | 123 | 4/5/2024 |
1.0.23 | 115 | 4/4/2024 |
1.0.22 | 108 | 4/4/2024 |
1.0.21 | 129 | 3/1/2024 |
1.0.20 | 117 | 2/2/2024 |
1.0.19 | 97 | 2/1/2024 |
1.0.18 | 135 | 1/20/2024 |
1.0.17 | 117 | 1/15/2024 |
1.0.16 | 99 | 1/14/2024 |
1.0.15 | 109 | 1/13/2024 |
1.0.14 | 117 | 1/11/2024 |
1.0.13 | 180 | 11/4/2023 |
1.0.12 | 124 | 10/12/2023 |
1.0.11 | 165 | 7/22/2023 |