Doku.Common.Shared
1.0.9
Additional Details
kaldırıldı
dotnet add package Doku.Common.Shared --version 1.0.9
NuGet\Install-Package Doku.Common.Shared -Version 1.0.9
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="Doku.Common.Shared" Version="1.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Doku.Common.Shared" Version="1.0.9" />
<PackageReference Include="Doku.Common.Shared" />
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 Doku.Common.Shared --version 1.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Doku.Common.Shared, 1.0.9"
#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 Doku.Common.Shared@1.0.9
#: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=Doku.Common.Shared&version=1.0.9
#tool nuget:?package=Doku.Common.Shared&version=1.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Doku.Common.Shared
Doku.Common.Shared is a .NET 9 library containing shared common utilities, result patterns, and cross-cutting concerns for the Doku framework.
?? Installation
dotnet add package Doku.Common.Shared
or in Package Manager Console:
Install-Package Doku.Common.Shared
?? Features
- Result Pattern: Type-safe operation results with success/failure states
- Paged Results: Standardized pagination support
- Validation Results: Structured validation error handling
- Shared Utilities: Common utility functions
- Helper Classes: Frequently used helper classes
?? Usage
Result Pattern
using Doku.Common.Results;
// Success result without value
public IResult CreateProduct(Product product)
{
// Business logic
return Result.Success();
}
// Success result with value
public IResult<int> CreateProduct(Product product)
{
var productId = SaveProduct(product);
return Result.Success(productId);
}
// Failure result
public IResult<Product> GetProduct(int id)
{
var product = FindProduct(id);
if (product == null)
return Result.Failure<Product>("Product not found");
return Result.Success(product);
}
// Multiple errors
public IResult ValidateProduct(Product product)
{
var errors = new List<string>();
if (string.IsNullOrEmpty(product.Name))
errors.Add("Product name is required");
if (product.Price <= 0)
errors.Add("Product price must be greater than 0");
if (errors.Any())
return Result.Failure(errors);
return Result.Success();
}
// Using the result
var result = CreateProduct(newProduct);
if (result.IsSuccess)
{
Console.WriteLine("Product created successfully");
}
else
{
Console.WriteLine($"Error: {result.Error}");
// or iterate all errors
foreach (var error in result.Errors)
Console.WriteLine(error);
}
// Implicit conversion for Result<T>
IResult<int> result = GetProductId();
int productId = result; // Throws if result is failure
Paged Results
using Doku.Common.Results;
public IPagedResult<Product> GetProducts(int pageNumber, int pageSize)
{
var totalCount = _repository.Count();
var items = _repository
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToList();
return PagedResult<Product>.Create(items, pageNumber, pageSize, totalCount);
}
// Using paged result
var pagedProducts = GetProducts(1, 10);
Console.WriteLine($"Page {pagedProducts.PageNumber} of {pagedProducts.TotalPages}");
Console.WriteLine($"Total items: {pagedProducts.TotalCount}");
Console.WriteLine($"Has next page: {pagedProducts.HasNextPage}");
foreach (var product in pagedProducts.Items)
{
Console.WriteLine(product.Name);
}
// Empty result
var emptyResult = PagedResult<Product>.Empty();
Validation Results
using Doku.Common.Results;
public IValidationResult ValidateProduct(Product product)
{
var errors = new List<IValidationError>();
if (string.IsNullOrEmpty(product.Name))
errors.Add(ValidationError.Create("Name", "Product name is required", "REQUIRED"));
if (product.Price <= 0)
errors.Add(ValidationError.Create("Price", "Price must be greater than 0", "INVALID_RANGE"));
if (errors.Any())
return ValidationResult.Invalid(errors);
return ValidationResult.Valid();
}
// Using validation result
var validationResult = ValidateProduct(product);
if (validationResult.IsValid)
{
SaveProduct(product);
}
else
{
foreach (var error in validationResult.ValidationErrors)
{
Console.WriteLine($"{error.PropertyName}: {error.ErrorMessage} ({error.ErrorCode})");
}
}
// Quick single error validation
var result = ValidationResult.Invalid("Email", "Invalid email format", "INVALID_FORMAT");
Combining with CQRS
using Doku.Common.CQRS;
using Doku.Common.Results;
// Command handler returning Result
public class CreateProductCommandHandler : ICommandHandler<CreateProductCommand, IResult<int>>
{
public async Task<IResult<int>> HandleAsync(CreateProductCommand command, CancellationToken cancellationToken)
{
// Validate
var validationResult = ValidateCommand(command);
if (!validationResult.IsValid)
return Result.Failure<int>(validationResult.Errors);
// Business logic
var product = MapToEntity(command);
var productId = await _repository.AddAsync(product);
return Result.Success(productId);
}
}
// Query handler returning PagedResult
public class GetProductsQueryHandler : IQueryHandler<GetProductsQuery, IPagedResult<ProductDto>>
{
public async Task<IPagedResult<ProductDto>> HandleAsync(GetProductsQuery query, CancellationToken cancellationToken)
{
var totalCount = await _repository.CountAsync();
var products = await _repository
.Skip((query.PageNumber - 1) * query.PageSize)
.Take(query.PageSize)
.ToListAsync();
var dtos = _mapper.Map<ProductDto>(products);
return PagedResult<ProductDto>.Create(dtos, query.PageNumber, query.PageSize, totalCount);
}
}
?? Requirements
- .NET 9.0 or higher
?? Dependencies
- Doku.Core (>= 1.0.16)
?? Contributing
If you would like to contribute to the project, please fork the repository and submit a pull request.
?? License
This project is developed by Doku team.
?? Links
?? Contact
For questions, please contact the Doku team.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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.
-
net9.0
- Doku.Core (>= 1.0.20)
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.9 | 239 | 10/31/2025 | |
| 1.0.6 | 279 | 10/30/2025 | |
| 1.0.0-beta.7 | 165 | 10/31/2025 | |
| 1.0.0-beta.5 | 209 | 10/30/2025 | |
| 1.0.0-beta.3 | 209 | 10/30/2025 |