Liquid.Repository.Mongo

Package Description


Keywords
License
MIT
Install
Install-Package Liquid.Repository.Mongo -Version 2.0.2-alpha

Documentation

Liquid Application Framework - Repository

This repository is part of the Liquid Application Framework, a modern Dotnet Core Application Framework for building cloud native microservices.

The main repository contains the examples and documentation on how to use Liquid.

Liquid.Repository

Quality Gate Status

This package contains the repository subsystem of Liquid, along with several databases implementation. In order to use it, add the database package (Liquid.Repository.Mongo for example) you need to your project, along with the specific implementation that you will need.

Available Cartridges Badges
Liquid.Repository.Mongo Quality Gate Status
Liquid.Repository.EntityFramework Quality Gate Status

Getting Started

This is a sample usage with MongoDb cartridge

Implement your entity and repository using Liquid inheritance

using Liquid.Repository;
public class MySampleModel : RepositoryEntity<int>
{
    public override int Id { get => base.Id; set => base.Id = value; }
    public string MyProperty { get; set; }
    public int MyProperty2 { get; set; }
    public DateTime MyProperty3 { get; set; }        
}
using Liquid.Repository.Mongo;
//the type of your repository must be the entity related to it.
 interface IMySampleRepository : ILightRepository<MySampleModel, int>
 {
     //Liquid inheritance provides the basic CRUD operations, but you can implement other methods specifically for your application's needs.
 }
//the type of your repository must be the entity related to it.
public class MySampleRepository : MongoRepository<MySampleModel, int>, IMySampleRepository
    {
        public MySampleRepository(ILightTelemetryFactory telemetryFactory, IMongoDataContext dataContext) 
            : base(telemetryFactory, dataContext)
        {
        }
        //Liquid inheritance provides the basic CRUD operations, but you can implement other methods specifically for your application's needs.
    }

Include dependency in domain class constructor, and invoke methods

public class MySampleDomainClass 
{
    private private IMySampleRepository _repository;

    public MySampleDomainClass(IMySampleRepository repository)
    {
         _repository = repository;
    }
    public async Task Handle()
    {
        //just invoke repository methods
        var entity = await _repository.FindByIdAsync(123);

        await _repository.UpdateAsync(entity);
    }
}

Dependency Injection

services.AddDefaultTelemetry();
services.AddDefaultContext();
services.AddConfigurations(GetType().Assembly);
//the first parameter value must be de configuration section name where connection string is declared.
services.AddMongo("sample", GetType().Assembly);

appsettings.json

"databases": {
      "mongo" : {
        "sample": {
          "connectionString": "",
          "databaseName": "MySampleDb"
        }
      }
    }
  }