NoSql.Core 1.0.3

dotnet add package NoSql.Core --version 1.0.3
                    
NuGet\Install-Package NoSql.Core -Version 1.0.3
                    
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="NoSql.Core" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NoSql.Core" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="NoSql.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NoSql.Core --version 1.0.3
                    
#r "nuget: NoSql.Core, 1.0.3"
                    
#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.
#:package NoSql.Core@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NoSql.Core&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=NoSql.Core&version=1.0.3
                    
Install as a Cake Tool

Library .NET - NoSQL

Introdução

Esta é uma biblioteca genérica em .NET, criada para facilitar o uso de bancos NoSQL, atualmente englobando Redis e MongoDB. A biblioteca estabelece conexão automática ao Redis e ao MongoDB utilizando injeção de dependência. Além disso, inclui diversas operações pré-definidas para facilitar a manipulação de dados nesses bancos.

Recursos

  • Conexão automática ao Redis e ao MongoDB.
  • Configuração simples via Singleton.
  • Operações CRUD pré-implementadas para ambos os bancos.
  • Suporte para cache no Redis.
  • Facilidade na gestão de coleções no MongoDB.

Instalação

Adicione a biblioteca ao seu projeto via NuGet:

Install-Package NoSql.Core

Configuração

Adicione os singletons que deseja usar, é necessário adicionar tanto o de conexão quando o de operações do DataBase.

builder.Services.AddSingleton<IConnectionMongoDB, ConnectionMongoDB>();
builder.Services.AddSingleton<IMongoOperations, MongoOperations>();

builder.Services.AddSingleton<IConnectionRedis, ConnectionRedis>();
builder.Services.AddSingleton<IRedisOperation, RedisOperations>();

Adicione as strings de conexão no AppSettings com os devidos nomes:

"MongoConnection": "String de conexão do mongo",
"MongoDataBaseConnection": "nome do DataBase mongo",
"RedisConnection": "String de conexão redis:porta do redis,password=Sua senha"

Uso

Exemplos para uso de métodos do mongo:

    public class MongoDocumentTRA
    {
        private readonly IMongoOperations _mongoOperations;

        public MongoDocumentTRA (IMongoOperations mongoOperations)
        {
            _mongoOperations = mongoOperations;
        }

        public void SavePerson(Person person)
        {
            _mongoOperations.InsertInMongoAsync(person, "Bmi");
        }

        public async Task<List<Person>> GetPersonListAsync(Person person)
        {

            List<Person> people = await _mongoOperations.GetListInMongoAsync<Person>(p =>
                                                              p.Name == person.Name &&
                                                              p.Id_user == person.Id_user,
                                                              "Bmi");
            return people;
        }

        public List<Person> GetPersonList(Person person)
        {

            List<Person> people = _mongoOperations.GetListInMongo<Person>(p =>
                                                              p.Name == person.Name &&
                                                              p.Id_user == person.Id_user,
                                                              "Bmi");
            return people;
        }

        public Person GetPerson(Person person)
        {

           Person personGet = _mongoOperations.GetInMongo<Person>(p =>
                                                                  p.PersonId == person.PersonId,
                                                                  "Bmi");
            return personGet;
        }

        public async Task<Person> GetPersonAsync(Person person)
        {

            Person personGet = await _mongoOperations.GetInMongoAsync<Person>(p =>
                                                                   p.PersonId == person.PersonId,
                                                                   "Bmi");
            return personGet;
        }

        public void UpdatePerson(Person person)
        {
            _mongoOperations.UpdateInMongoAsync<Person>( p =>
                                                p.PersonId == person.PersonId &&
                                                p.Id_user == person.Id_user,
                                                "Bmi", 
                                                person);
        }

        public void DeletePerson(Person person)
        {
            _mongoOperations.DeleteInMongoAsync<Person>(p =>
                                                p.PersonId == person.PersonId &&
                                                p.Id_user == person.Id_user,
                                                "Bmi");
        }
    }

Exemplos para uso de métodos do Redis:


    public class RedisTRA
    {
        private readonly IRedisOperation _redisOperation;

        public RedisTRA(IRedisOperation redisOperation)
        {
            _redisOperation = redisOperation;
        }

        public void PersonSetData(Person person, string redisKey)
        {
            _redisOperation.SetData(person, redisKey);
        }

        public Person PersonGetData(Person person, string redisKey)
        {
            Person personInCache = _redisOperation.GetData<Person>(redisKey);

            return person;
        }
        
        public List<Person> PersonGetAllDataByNameAndUserId(Person person, string redisKey)
        {
            List<Person> people = _redisOperation.GetAllDataByKey<Person>(redisKey);

            return people;
        }
    }

Contribuição

Sinta-se à vontade para abrir issues e pull requests para melhorias na biblioteca.

Licença

Este projeto está licenciado sob a MIT License - veja o arquivo LICENSE para mais detalhes.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.3 212 7/17/2025
1.0.2 194 7/16/2025
1.0.1 193 7/16/2025
1.0.0 171 2/8/2025