VersaTul.Data.MongoDB 1.0.23

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

// Install VersaTul.Data.MongoDB as a Cake Tool
#tool nuget:?package=VersaTul.Data.MongoDB&version=1.0.23                

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 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. 
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.26 77 10/12/2024
1.0.25 88 10/5/2024
1.0.24 117 4/5/2024
1.0.23 109 4/4/2024
1.0.22 102 4/4/2024
1.0.21 123 3/1/2024
1.0.20 111 2/2/2024
1.0.19 91 2/1/2024
1.0.18 127 1/20/2024
1.0.17 111 1/15/2024
1.0.16 93 1/14/2024
1.0.15 103 1/13/2024
1.0.14 111 1/11/2024
1.0.13 174 11/4/2023
1.0.12 118 10/12/2023
1.0.11 157 7/22/2023