qs.LibPack.MongoDB
8.1.0
dotnet add package qs.LibPack.MongoDB --version 8.1.0
NuGet\Install-Package qs.LibPack.MongoDB -Version 8.1.0
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="qs.LibPack.MongoDB" Version="8.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="qs.LibPack.MongoDB" Version="8.1.0" />
<PackageReference Include="qs.LibPack.MongoDB" />
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 qs.LibPack.MongoDB --version 8.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: qs.LibPack.MongoDB, 8.1.0"
#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 qs.LibPack.MongoDB@8.1.0
#: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=qs.LibPack.MongoDB&version=8.1.0
#tool nuget:?package=qs.LibPack.MongoDB&version=8.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
qsLibPack.MongoDB
Integração com MongoDB para qsLibPack: contexto, repositório base e unidade de trabalho com DI.
Instalação
dotnet add package qs.LibPack.MongoDB --version 8.1.0
Exemplos
Básico
Registrar serviços com DI e configurar conexão.
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using qsLibPack.Repositories.Mongo.Extensions;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false)
.Build();
var services = new ServiceCollection();
services.AddQsLibPackMongoDB(configuration);
var provider = services.BuildServiceProvider();
appsettings.json:
{
"MongoConnection": {
"ConnectionString": "mongodb://localhost:27017",
"Database": "mydb"
}
}
Intermediário
Criar repositório concreto e realizar operações com commit.
using System;
using System.Threading.Tasks;
using qsLibPack.Domain.Entities;
using qsLibPack.Repositories.Interfaces;
using qsLibPack.Repositories.Mongo;
using qsLibPack.Repositories.Mongo.Core;
public sealed class User : AggregateRoot<Guid>
{
public string Name { get; set; }
public override void Validate()
{
if (string.IsNullOrEmpty(Name)) throw new qsLibPack.Domain.Exceptions.DomainException("Nome obrigatório");
}
}
public sealed class UserRepository : Repository<User, Guid>
{
public UserRepository(IMongoContext ctx) : base(ctx) { }
}
// Uso
var repo = provider.GetRequiredService<UserRepository>();
var uow = provider.GetRequiredService<IUnitOfWork>();
var user = new User { Id = Guid.NewGuid(), Name = "Alice" };
await repo.CreateAsync(user);
await uow.CommitAsync();
Avançado
Executar múltiplas operações e consultar por id.
// Atualizar
user.Name = "Alice Silva";
await repo.UpdateAsync(user);
// Remover
await repo.RemoveAsync(user);
// Commit das operações pendentes
await uow.CommitAsync();
// Consulta por id
var loaded = await repo.GetByIDAsync(user.Id);
Informações do NuGet
- Versão atual: 8.1.0
- Dependências:
- MongoDB.Driver 3.5.1
- Microsoft.Extensions.DependencyInjection 8.*
- Microsoft.Extensions.Options.ConfigurationExtensions 8.*
- Compatibilidade: .NET 8 (net8.0)
- Link direto: https://www.nuget.org/packages/qs.LibPack.MongoDB/
- Histórico (resumo):
- 8.0.0: suporte a net8.0, ajustes de DI e empacotamento do README
- 8.1.0:
MongoContextregistraIMongoClientcomo singleton (preserva connection pool) e executa os comandos do Unit of Work sequencialmente, limpando a fila mesmo em caso de erro;GetByID/GetByIDAsyncretornam tipo anulável; Nullable habilitado
Como Contribuir
- Abra issues/PRs no repositório principal
- Mantenha exemplos compatíveis com a API atual
- Valide localmente com uma instância MongoDB antes de enviar PR
Links
- Repositório: https://github.com/danilodumba/qsLibPack
- Documentação relacionada: qsLibPack
| Product | Versions 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.
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- MongoDB.Driver (>= 3.5.1)
- qs.LibPack (>= 8.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.