Flowsy.Db.Repository.Abstractions
1.0.0
dotnet add package Flowsy.Db.Repository.Abstractions --version 1.0.0
NuGet\Install-Package Flowsy.Db.Repository.Abstractions -Version 1.0.0
<PackageReference Include="Flowsy.Db.Repository.Abstractions" Version="1.0.0" />
paket add Flowsy.Db.Repository.Abstractions --version 1.0.0
#r "nuget: Flowsy.Db.Repository.Abstractions, 1.0.0"
// Install Flowsy.Db.Repository.Abstractions as a Cake Addin #addin nuget:?package=Flowsy.Db.Repository.Abstractions&version=1.0.0 // Install Flowsy.Db.Repository.Abstractions as a Cake Tool #tool nuget:?package=Flowsy.Db.Repository.Abstractions&version=1.0.0
Flowsy Db Abstractions
Repository
The interface IRepository represents a mechanism to encapsulate the logic for accessing data in the form of entities, independently of the underlying data store.
Unit Of Work
The interface IUnitOfWork represents an atomic operation for the underlying data store. For a SQL database, a class implementing IUnitOfWork could be a wrapper for IRepository instances sharing a single IDbTransaction object.
For example, to create an invoice, we may need to create two kinds of entities:
- Invoice
- InvoiceId
- CustomerId
- CreateDate
- Total
- Taxes
- GrandTotal
- InvoiceItem
- InvoiceItemId
- InvoiceId
- ProductId
- Quantity
- Amount
The way of completing such operation from an application-level command handler could be:
public class IInvoiceRepository : IRepository
{
Task CreateInvoiceAsync(Invoice invoice, CancellationToken cancellationToken);
}
public class IInvoiceItemRepository : IRepository
{
Task CreateInvoiceItemAsync(InvoiceItem invoiceItem, CancellationToken cancellationToken);
}
public interface ISalesUnitOfWork : IUnitOfWork
{
IInvoiceRepository InvoiceRepository { get; }
IInvoiceItemRepository InvoiceItemRepository { get; }
}
public class CreateInvoiceCommandHandler
{
private readonly ISalesUnitOfWork _unitOfWork;
public CreateInvoiceCommandHandler(ISalesUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<CreateInvoiceCommandResult> HandleAsync(CreateInvoiceCommand command, CancellationToken cancellationToken)
{
// Validate command
var invoice = new Invoice();
// Populate invoice object from properties of command object
// Begin operation
// IUnitOfWork inherits from IDisposable and IAsyncDisposable, if any exception is thrown, the current operation shall be rolled back
_unitOfWork.BeginWork();
// Create the Invoice entity
var invoiceId = await _unitOfWork.InvoiceRepository.CreateInvoiceAsync(invoice, cancellationToken);
// Create all the InvoiceItem entities
foreach (var item in command.Items)
{
var invoiceItem = new InvoiceItem();
// Populate invoiceItem object from properties of item object
// Create each InvoiceItem entity
await _unitOfWork.InvoiceItemRepository.CreateInvoiceItemAsync(invoiceItem, cancellationToken);
}
// Commit the current operation
await _unitOfWork.SaveWorkAsync(cancellationToken);
// Return the result of the operation
return new CreateInvoiceCommandResult
{
InvoiceId = invoiceId
};
}
}
Note: This document ommits implementation details of IRepository and IUnitOfWork interfaces, focusing on showing how they can be used to encapsulate the logic for creating multiple entities in a single atomic operation.
The Flowsy.Db.Repository.Sql package offers an implementation of IRepository and IUnitOfWork interfaces for SQL databases.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Flowsy.Db.Repository.Abstractions:
Package | Downloads |
---|---|
Flowsy.Db.Repository.Sql
Implementations of data repositories and related operations in the context of a unit of work using SQL databases. |
GitHub repositories
This package is not used by any popular GitHub repositories.