Acontplus.Core 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Acontplus.Core --version 1.3.1
                    
NuGet\Install-Package Acontplus.Core -Version 1.3.1
                    
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="Acontplus.Core" Version="1.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Acontplus.Core" Version="1.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Acontplus.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 Acontplus.Core --version 1.3.1
                    
#r "nuget: Acontplus.Core, 1.3.1"
                    
#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 Acontplus.Core@1.3.1
                    
#: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=Acontplus.Core&version=1.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Acontplus.Core&version=1.3.1
                    
Install as a Cake Tool

Acontplus.Core

NuGet .NET License

A modern .NET 9+ foundational library providing enterprise-grade components with domain-driven design patterns, comprehensive error handling, and modern C# features.

🚀 Features

🏗️ Core Architecture

  • Domain-Driven Design (DDD) - Complete DDD implementation with entities, value objects, and domain events
  • Modern Entity System - Base entities with audit trails, soft deletes, and domain event support
  • Specification Pattern - Flexible query specifications for complex business rules
  • Result Pattern - Functional error handling with modern .NET 9+ features

📊 Data Transfer Objects (DTOs)

  • Structured API Responses - Consistent API response format with status, errors, and metadata
  • Pagination Support - Built-in pagination DTOs for efficient data retrieval
  • Request/Response Models - Type-safe request and response models

🔍 Validation & Error Handling

  • Domain Errors - Comprehensive error types with HTTP status code mapping
  • Data Validation - Common validation utilities for XML, JSON, and data formats
  • Error Extensions - Fluent error handling with severity-based error aggregation

🎯 Modern .NET 9+ Features

  • Required Properties - Compile-time null safety with required properties
  • Collection Expressions - Modern collection initialization with [] syntax
  • Pattern Matching - Advanced pattern matching for type-safe operations
  • Source Generators - JSON serialization with source generation for performance
  • Nullable Reference Types - Full nullable reference type support

🆕 Modern JSON Extensions

Acontplus.Core provides high-performance, secure JSON utilities via Extensions/JsonExtensions:

  • Enterprise-optimized serialization: Consistent, camelCase, safe, and fast.
  • Multiple options: Default, Pretty (for debugging), and Strict (for APIs).
  • Extension methods: For easy serialization, deserialization, and deep cloning.
Usage Examples
using Acontplus.Core.Extensions;

// Serialize with enterprise defaults
var json = myObject.SerializeModern();

// Serialize with pretty formatting (for debugging)
var prettyJson = myObject.SerializeModern(pretty: true);

// Deserialize with enterprise defaults
var obj = jsonString.DeserializeModern<MyType>();

// Safe deserialization with fallback
var objOrDefault = jsonString.DeserializeModernSafe<MyType>(fallback: new MyType());

// Deep clone via JSON
var clone = myObject.CloneViaJson();

// Use options directly (for ASP.NET Core, etc.)
var options = JsonExtensions.DefaultOptions;

📦 Installation

NuGet Package Manager

Install-Package Acontplus.Core

.NET CLI

dotnet add package Acontplus.Core

PackageReference

<PackageReference Include="Acontplus.Core" Version="1.2.0" />

🎯 Quick Start

1. Basic Entity Usage

public class Product : AuditableEntity<int>
{
    public required string Name { get; set; }
    public required decimal Price { get; set; }
    public string? Description { get; set; }
    
    // Factory method for creating products
    public static Product Create(int id, string name, decimal price, int createdByUserId)
    {
        return new Product
        {
            Id = id,
            Name = name,
            Price = price,
            CreatedAt = DateTime.UtcNow,
            CreatedByUserId = createdByUserId
        };
    }
}

2. Domain Error Handling

// Create domain errors
var validationError = DomainError.Validation(
    code: "PRODUCT_INVALID_PRICE",
    message: "Product price must be greater than zero",
    target: "price"
);

var notFoundError = DomainError.NotFound(
    code: "PRODUCT_NOT_FOUND",
    message: "Product with ID {id} was not found",
    target: "id"
);

// Convert to API response
var response = validationError.ToApiResponse<ProductDto>();

3. Result Pattern Usage

public async Task<Result<Product>> GetProductAsync(int id)
{
    var product = await _repository.GetByIdAsync(id);
    
    return product is not null 
        ? Result<Product>.Success(product)
        : Result<Product>.Failure(DomainError.NotFound("PRODUCT_NOT_FOUND", $"Product {id} not found"));
}

// Usage with pattern matching
var result = await GetProductAsync(123);
var response = result.Match(
    success: product => ApiResponse<Product>.Success(product),
    failure: error => error.ToApiResponse<Product>()
);

4. Specification Pattern

public class ActiveProductsSpecification : BaseSpecification<Product>
{
    public ActiveProductsSpecification(PaginationDto pagination) : base(p => p.IsActive)
    {
        ApplyPaging(pagination);
        AddOrderBy(p => p.CreatedAt, isDescending: true);
        AddInclude(p => p.Category);
    }
}

// Usage
var spec = new ActiveProductsSpecification(new PaginationDto { Page = 1, PageSize = 10 });
var products = await _repository.FindWithSpecificationAsync(spec);

5. API Response Handling

[HttpGet("{id}")]
public async Task<ApiResponse<ProductDto>> GetProduct(int id)
{
    var product = await _productService.GetByIdAsync(id);
    
    if (product is null)
    {
        return ApiResponse<ProductDto>.Failure(
            DomainError.NotFound("PRODUCT_NOT_FOUND", $"Product {id} not found")
        );
    }
    
    return ApiResponse<ProductDto>.Success(product.ToDto());
}

🔧 Advanced Usage

Domain Events

public class ProductCreatedEvent : IDomainEvent
{
    public int ProductId { get; }
    public string ProductName { get; }
    public DateTime OccurredOn { get; }
    
    public ProductCreatedEvent(int productId, string productName)
    {
        ProductId = productId;
        ProductName = productName;
        OccurredOn = DateTime.UtcNow;
    }
}

// In your entity
public void MarkAsCreated()
{
    AddDomainEvent(new ProductCreatedEvent(Id, Name));
}

Repository Pattern

public interface IProductRepository : IRepository<Product, int>
{
    Task<IReadOnlyList<Product>> GetByCategoryAsync(int categoryId);
    Task<bool> ExistsByNameAsync(string name);
}

public class ProductRepository : BaseRepository<Product, int>, IProductRepository
{
    public ProductRepository(DbContext context) : base(context) { }
    
    public async Task<IReadOnlyList<Product>> GetByCategoryAsync(int categoryId)
    {
        return await FindAsync(p => p.CategoryId == categoryId);
    }
    
    public async Task<bool> ExistsByNameAsync(string name)
    {
        return await ExistsAsync(p => p.Name == name);
    }
}

Error Aggregation

public async Task<Result<Product>> CreateProductAsync(CreateProductRequest request)
{
    var errors = new List<DomainError>();
    
    if (string.IsNullOrWhiteSpace(request.Name))
        errors.Add(DomainError.Validation("INVALID_NAME", "Product name is required"));
    
    if (request.Price <= 0)
        errors.Add(DomainError.Validation("INVALID_PRICE", "Price must be greater than zero"));
    
    if (await _repository.ExistsByNameAsync(request.Name))
        errors.Add(DomainError.Conflict("DUPLICATE_NAME", "Product name already exists"));
    
    if (errors.Any())
        return Result<Product>.Failure(errors.GetMostSevereError());
    
    var product = Product.Create(request.Name, request.Price, request.CreatedByUserId);
    await _repository.AddAsync(product);
    
    return Result<Product>.Success(product);
}

🏗️ Architecture Patterns

Domain-Driven Design

  • Entities: Rich domain objects with identity and lifecycle
  • Value Objects: Immutable objects representing concepts
  • Domain Events: Decoupled communication between aggregates
  • Specifications: Encapsulated business rules for queries

Repository Pattern

  • Generic Repository: Type-safe data access with common operations
  • Specification Pattern: Flexible query composition
  • Unit of Work: Transaction management and consistency

Error Handling

  • Domain Errors: Business logic errors with proper categorization
  • Result Pattern: Functional error handling without exceptions
  • API Responses: Consistent error response format

🔍 Validation Examples

// XML Validation
if (!DataValidation.IsXml(xmlContent))
{
    return DomainError.Validation("INVALID_XML", "Invalid XML format");
}

// JSON Validation
if (!DataValidation.IsValidJson(jsonContent))
{
    return DomainError.Validation("INVALID_JSON", "Invalid JSON format");
}

// IP Address Validation
var validIp = DataValidation.ValidateIpAddress("192.168.1.1");

📚 API Documentation

Entity Base Classes

  • Entity<TId> - Base entity with domain events
  • AuditableEntity<TId> - Entity with audit trail and soft delete
  • BaseEntity - Convenience base for int-keyed entities

DTOs

  • ApiResponse<T> - Standardized API response format
  • PaginationDto - Pagination parameters
  • ApiError - Detailed error information

Error Handling

  • DomainError - Business logic errors
  • Result<T> - Functional result pattern
  • ErrorType - Categorized error types

Repository

  • IRepository<TEntity, TId> - Generic repository interface
  • ISpecification<T> - Query specification pattern
  • PagedResult<T> - Paginated query results

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

git clone https://github.com/Acontplus-S-A-S/acontplus-dotnet-libs.git
cd acontplus-dotnet-libs
dotnet restore
dotnet build

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

  • 📧 Email: proyectos@acontplus.com
  • 🐛 Issues: GitHub Issues
  • 📖 Documentation: Wiki

👨‍💻 Author

Ivan Paz - @iferpaz7

🏢 Company

Acontplus S.A.S. - Enterprise software solutions


Built with ❤️ for the .NET community

Product 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

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on Acontplus.Core:

Package Downloads
Acontplus.Persistence.SqlServer

Advanced library for SQL Server persistence with Entity Framework Core integration. Includes repositories, context management, ADO.NET support, advanced error handling, and enterprise-ready data access patterns for SQL Server databases.

Acontplus.Services

Comprehensive library for API services, authentication, claims, middleware, and configuration. Includes JWT authentication, user context management, exception handling, security headers, and enterprise-ready service patterns for ASP.NET Core applications.

Acontplus.Utilities

Comprehensive utilities library with cross-cutting concerns and general-purpose tools. Includes encryption, IO operations, text processing, time utilities, API helpers, JSON utilities, and security features for enterprise applications.

Acontplus.Reports

Advanced library for comprehensive report generation and management. Includes RDLC report processing, PDF/Excel export capabilities, ReportViewer integration, template support, and enterprise-ready reporting patterns for business applications.

Acontplus.Notifications

Comprehensive library for notification services. Includes email (MailKit, Amazon SES), WhatsApp, push notifications, templating with Scriban, queue management, and enterprise-ready delivery patterns for cloud-native applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.5 51 9/23/2025
1.5.4 214 9/14/2025
1.5.3 179 9/14/2025
1.5.2 215 9/14/2025
1.5.1 216 9/14/2025
1.5.0 168 9/9/2025
1.4.7 223 8/21/2025
1.4.6 123 8/21/2025
1.4.5 160 8/19/2025
1.4.4 189 8/8/2025
1.4.3 147 8/8/2025
1.4.2 241 8/7/2025
1.4.1 219 8/7/2025
1.4.0 218 8/7/2025
1.3.2 595 7/23/2025
1.3.1 177 7/18/2025
1.3.0 228 7/14/2025
1.2.10 136 7/14/2025
1.2.9 175 7/14/2025
1.2.8 123 7/11/2025
1.2.7 136 7/11/2025
1.2.6 181 7/10/2025
1.2.5 137 7/10/2025
1.2.4 141 7/10/2025
1.2.3 135 7/10/2025
1.2.2 138 7/10/2025
1.2.1 173 7/10/2025
1.2.0 173 7/10/2025
1.1.11 177 7/9/2025
1.1.10 249 7/6/2025
1.1.9 138 7/6/2025
1.1.8 141 7/6/2025
1.1.7 180 7/6/2025
1.1.6 143 7/6/2025
1.1.5 148 7/6/2025
1.1.4 162 7/4/2025
1.1.3 202 7/2/2025
1.1.2 176 7/2/2025
1.1.1 141 7/2/2025
1.1.0 210 7/1/2025

Updated for .NET 9+ with modern C# features, improved error handling, and enhanced documentation