Gleeman.Repository.MongoDriver 7.0.1

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

// Install Gleeman.Repository.MongoDriver as a Cake Tool
#tool nuget:?package=Gleeman.Repository.MongoDriver&version=7.0.1                

Gleeman.Repository.MongoDriver

Command Repositories

Create
public interface IMongoCreateAsyncRepository<TCollection>
    where TCollection : class
{
    Task<TCollection> CreateAsync(TCollection document, CancellationToken cancellationToken = default(CancellationToken));
    Task InsertAsync(TCollection document, CancellationToken cancellationToken = default(CancellationToken));
    Task<IEnumerable<TCollection>> CreateRangeAsync(IEnumerable<TCollection> documents, CancellationToken cancellationToken = default(CancellationToken));
    Task InsertRangeAsync(IEnumerable<TCollection> documents, CancellationToken cancellationToken = default(CancellationToken));
}
public interface IMongoCreateSyncRepository<TCollection>
    where TCollection : class
{
    TCollection Create(TCollection document);
    void Insert(TCollection document);
    IEnumerable<TCollection> CreateRange(IEnumerable<TCollection> documents);
    void InsertRange(IEnumerable<TCollection> documents);
}
Delete
public interface IMongoDeleteAsyncRepository<TCollection>
    where TCollection : class
{
    Task DeleteAsync(FilterDefinition<TCollection> filter, CancellationToken cancellationToken = default(CancellationToken));
    Task DeleteRangeAsync(FilterDefinition<TCollection> filter, CancellationToken cancellationToken = default(CancellationToken));
}
public interface IMongoDeleteSyncRepository<TCollection>
    where TCollection : class
{

    void Delete(FilterDefinition<TCollection> filter);
    void DeleteRange(FilterDefinition<TCollection> filter);
}
Update
public interface IMongoUpdateAsyncRepository<TCollection>
    where TCollection : class
{
    Task<TCollection> UpdateAsync(FilterDefinition<TCollection> filter, TCollection collection, CancellationToken cancellationToken = default);
    Task EditAsync(FilterDefinition<TCollection> filter, TCollection collection, CancellationToken cancellationToken = default);
    Task EditRangeAsync(FilterDefinition<TCollection> filter, UpdateDefinition<TCollection> update, CancellationToken cancellationToken = default);
}
public interface IMongoUpdateSyncRepository<TCollection>
    where TCollection : class
{
    TCollection Update(FilterDefinition<TCollection> filter, TCollection collection);
    void Edit(FilterDefinition<TCollection> filter, TCollection collection);
    void EditRange(FilterDefinition<TCollection> filter, UpdateDefinition<TCollection> update);
}

Query Repositories

public interface IMongoQueryAsyncRepository<TCollection>
    where TCollection : class
{
    Task<IEnumerable<TCollection>> ReadAllAsync(CancellationToken cancellationToken = default(CancellationToken), 
        Expression<Func<TCollection, bool>> filter = null, 
        Action<Pagination> pagination = null);
    Task<TCollection> ReadSingleOrDefaultAsync(Expression<Func<TCollection, bool>> filter, 
        CancellationToken cancellationToken = default(CancellationToken));

    Task<TCollection> ReadFirstOrDefaultAsync(Expression<Func<TCollection, bool>> filter, 
        CancellationToken cancellationToken = default(CancellationToken));

    Task<TCollection> ReadSingleAsync(Expression<Func<TCollection, bool>> filter, 
        CancellationToken cancellationToken = default(CancellationToken));

    Task<TCollection> ReadFirstAsync(Expression<Func<TCollection, bool>> filter,
        CancellationToken cancellationToken = default(CancellationToken));
}
public interface IMongoQuerySyncRepository<TCollection>
    where TCollection : class
{
    IEnumerable<TCollection> ReadAll(Expression<Func<TCollection, bool>> filter = null, Action<Pagination> pagination = null);
    TCollection ReadSingleOrDefault(Expression<Func<TCollection, bool>> filter);
    TCollection ReadFirstOrDefaut(Expression<Func<TCollection, bool>> filter);
    TCollection ReadSingle(Expression<Func<TCollection, bool>> filter);
    TCollection ReadFirst(Expression<Func<TCollection, bool>> filter);
}

USAGE

Program.cs
using Gleeman.Repository.MongoDriver.Configuration;
builder.Services.AddMongoRepository(builder.Configuration);
appsettings.json
 "MongoOption": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "CustomerDB"
  }
// Command
public interface ICustomerCommandRepository : IMongoCreateAsyncRepository<Customer>
{
}


public class CustomerCommandRepository : MongoCommandRepository<Customer>, ICustomerCommandRepository
{
    public CustomerCommandRepository(IMongoOptions option) : base(option)
    {
    }
}

// Query
public interface ICustomerQueryRepository : IMongoQueryAsyncRepository<Customer>
{
}

public class CustomerQueryRepository : MongoQueryRepository<Customer>, ICustomerQueryRepository
{
    public CustomerQueryRepository(IMongoOptions option) : base(option)
    {
    }
}

[Route("api/[controller]")]
[ApiController]
public class CustomersController : ControllerBase
{
    private readonly ICustomerQueryRepository _query;
    private readonly ICustomerCommandRepository _command;

    public CustomersController(ICustomerQueryRepository query, ICustomerCommandRepository command)
    {
        _query = query;
        _command = command;
    }

    [HttpGet]
    public async Task<IActionResult>GetCustomers()
    {
        var result = await _query.ReadAllAsync();
        return Ok(result);
    }

    [HttpPost]
    public async Task<IActionResult>CreateCustomer(Customer customer)
    {
        var result = await _command.CreateAsync(customer);
        return Ok(result);
    }
}

2 1

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
7.0.2 183 1/5/2024
7.0.1 130 12/31/2023
7.0.0 201 10/21/2023