MongoDbGenericRepositoryPattern 1.0.1

dotnet add package MongoDbGenericRepositoryPattern --version 1.0.1                
NuGet\Install-Package MongoDbGenericRepositoryPattern -Version 1.0.1                
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="MongoDbGenericRepositoryPattern" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDbGenericRepositoryPattern --version 1.0.1                
#r "nuget: MongoDbGenericRepositoryPattern, 1.0.1"                
#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 MongoDbGenericRepositoryPattern as a Cake Addin
#addin nuget:?package=MongoDbGenericRepositoryPattern&version=1.0.1

// Install MongoDbGenericRepositoryPattern as a Cake Tool
#tool nuget:?package=MongoDbGenericRepositoryPattern&version=1.0.1                

License

License: MIT

Features

"Hello, I would like to talk about the features of MongoDbGenericRepositoryPattern, a NuGet package I wrote."

  • You can work with asynchronous or non-asynchronous methods.
  • You can use it in your sample projects. It will speed you up.
  • There are crud operations.
  • When you configure appsettings and program.cs, it will run smoothly.
  • I am using it in a real microservice project. (own project)
  • More methods will be added.

Errors are corrected as a result of feedback.

MongoDbGenericRepositoryPattern- 1.0.1

A nuget package I wrote to use the generic repository pattern more efficiently.

Version

.net 7.0

Install

  dotnet add package MongoDbGenericRepositoryPattern --version 1.0.1

Use

Appsettings.json

{
  "DatabaseSettings": {
    "ConnectionStrings": "mongodb://localhost:27017",
    "DatabaseName": "ProductDb"
  }
}

Program.cs

builder.Services.AddScoped<ICategoryService, CategoryService>();
builder.Services.AddScoped<IProductRepository, ProductRepository>();
builder.Services.Configure<DatabaseSettings>(builder.Configuration.GetSection("DatabaseSettings"));
builder.Services.AddSingleton<IDatabaseSettings>(sp =>
{
    return sp.GetRequiredService<IOptions<DatabaseSettings>>().Value;
});

Create Repository

* Interface
    public interface IProductRepository :IRepository<Products>
    {
        void AddProduct(Products product);
    }



  *  Concrete  
public class ProductRepository : MongoDbGenericRepository<Products>, IProductRepository
{
    private readonly MongoDbContext _dbContext;

    public ProductRepository(IDatabaseSettings databaseSettings) : base(databaseSettings)
    {
        _dbContext = new MongoDbContext(databaseSettings);
    }

    public void AddProduct(Products product)
    {
        var collection = _dbContext.GetCollection<Products>();
        collection.InsertOne(product);
    }
}


Service

private readonly ICategoryRepository _categoryRepository;
private readonly IMapper _mapper;

public CategoryService(ICategoryRepository categoryRepository, IMapper mapper)
{
    _categoryRepository = categoryRepository;
   _mapper = mapper;
}

  public async Task<ResponseDto<List<CategoryDto>>> GetAllAsync()
{
    var categories = await _categoryRepository.GetAllAsync();
    var categoriesDto = _mapper.Map<List<CategoryDto>>(categories);

    return ResponseDto<List<CategoryDto>>.Success(categoriesDto, 200);
}

Controller

private readonly ICategoryService _categoryService;

public CategoryController(ICategoryService categoryService)
{
    _categoryService = categoryService;
}

[HttpGet("[action]")]
public async Task<IActionResult> GetAll()
{
    var response = await _categoryService.GetAllAsync();
    return CreateActionResultInstance(response);
}

IRepository

Task<bool> ExistsByIdAsync(string id, string type = "object");
IQueryable<T> GetAllQueryable();
Task<IQueryable<T>> GetAllQueryableAsync();
IList<T> GetAll();
Task<IList<T>> GetAllAsync();
IList<T> FilterBy(Expression<Func<T, bool>> filter);
Task<IList<T>> FilterByAsync(Expression<Func<T, bool>> filter);
T GetById(string id, string type = "object");
Task<T> GetByIdAsync(string id, string type = "object");
void InsertOne(T entity);
Task InsertOneAsync(T entity);
void InsertMany(ICollection<T> entities);
Task InsertManyAsync(ICollection<T> entities);
T UpdateOne(T entity, string id, string type = "object");
Task<T> UpdateOneAsync(T entity, string id, string type = "object");
T DeleteOne(Expression<Func<T, bool>> filter);
Task<T> DeleteOneAsync(Expression<Func<T, bool>> filter);
T DeleteById(string id);
Task<T> DeleteByIdAsync(string id);
void DeleteMany(Expression<Func<T, bool>> filter);
Task DeleteManyAsync(Expression<Func<T, bool>> filter);
## Packages

* Mongodb.Bson(2.20.0)
* Mongodb.Driver(2.20.0)
 ### Design Patterns:
    * Generic Repository   
    * Options   

                                                                                                                      
   ###    By Abdullah Balikci - berjcode

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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.1 181 7/21/2023
1.0.0 163 7/18/2023

Crud operations are available.