Advanced foundational library with cutting-edge C# features and 17 global business enums for multi-application standardization. Includes domain-driven design patterns, comprehensive error handling with HTTP mapping, specification pattern interfaces, functional result types, JSON utilities, validation helpers, and enterprise-ready abstractions. Features ready-to-use enums for business status, priorities, document types, demographics, currencies, payment methods, user roles, industries, company sizes, event types, and internationalization. Built with collection expressions, required properties, record structs, and source generation for optimal performance. Clean architecture with no persistence dependencies.
$ dotnet add package Acontplus.CoreA cutting-edge .NET 9+ foundational library leveraging the latest C# language features and modern enterprise patterns. Built with performance, type safety, and developer experience in mind.
[] syntax for efficient collection initializationrequired keywordswitch expressions and is patternsIAsyncEnumerable<T> for memory-efficient processing// Modern entity with required properties and collection expressions
public class Product : BaseEntity
{
public required string Name { get; set; }
public required decimal Price { get; set; }
public string? Description { get; set; }
public required int CategoryId { get; set; }
// Factory method with modern syntax
public static Product Create(int id, string name, decimal price, string description, int categoryId, int createdByUserId) =>
new()
{
Id = id,
Name = name,
Price = price,
Description = description,
CategoryId = categoryId,
CreatedAt = DateTime.UtcNow,
CreatedByUserId = createdByUserId
};
}// Modern result pattern with record structs
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"));
}
// Pattern matching with modern syntax
var response = result.Match(
success: product => ApiResponse<Product>.Success(product),
failure: error => error.ToApiResponse<Product>()
);// Collection expressions and modern initialization
var pagination = new PaginationDto
{
PageIndex = 1,
PageSize = 20,
SortBy = "CreatedAt",
SortDirection = SortDirection.Descending,
SearchTerm = "search term",
Filters = new Dictionary<string, object>
{
["CategoryId"] = 1,
["IsActive"] = true
}
};
// Modern 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);
}
}// Memory-efficient async streaming
await foreach (var product in repository.FindAsyncEnumerable(p => p.IsActive))
{
await ProcessProductAsync(product);
}
// High-performance projections
var summaries = await repository.GetPagedProjectionAsync(
pagination,
p => new ProductSummary(p.Id, p.Name, p.Price),
p => p.IsActive
);// Enterprise-optimized JSON with source generation
var json = myObject.SerializeModern();
var obj = jsonString.DeserializeModern<MyType>();
var clone = myObject.CloneViaJson();
// Modern JSON options for different scenarios
var options = JsonExtensions.DefaultOptions; // Production
var prettyOptions = JsonExtensions.PrettyOptions; // Development
var strictOptions = JsonExtensions.StrictOptions; // APIs// Modern error creation with record structs
var validationError = DomainError.Validation(
code: "PRODUCT_INVALID_PRICE",
message: "Product price must be greater than zero",
target: "price"
);
// Error aggregation with modern LINQ
var errors = new List<DomainError>();
if (string.IsNullOrWhiteSpace(request.Name))
errors.Add(DomainError.Validation("INVALID_NAME", "Product name is required"));
if (errors.Any())
return Result<Product>.Failure(errors.GetMostSevereError());Install-Package Acontplus.Coredotnet add package Acontplus.Core<PackageReference Include="Acontplus.Core" Version="1.3.3" />// Modern entity with required properties
public class Product : BaseEntity
{
public required string Name { get; set; }
public required decimal Price { get; set; }
public string? Description { get; set; }
public required int CategoryId { get; set; }
// Factory method with modern syntax
public static Product Create(int id, string name, decimal price, string description, int categoryId, int createdByUserId) =>
new()
{
Id = id,
Name = name,
Price = price,
Description = description,
CategoryId = categoryId,
CreatedAt = DateTime.UtcNow,
CreatedByUserId = createdByUserId
};
}// Modern error creation with record structs
var validationError = DomainError.Validation(
code: "PRODUCT_INVALID_PRICE",
message: "Product price must be greater than zero",
target: "price"
);
// Pattern matching with modern syntax
var response = result.Match(
success: product => ApiResponse<Product>.Success(product),
failure: error => error.ToApiResponse<Product>()
);// Modern repository interface
public interface IProductRepository : IRepository<Product>
{
Task<IReadOnlyList<Product>> GetByCategoryAsync(int categoryId);
Task<bool> ExistsByNameAsync(string name);
}
// Modern repository implementation
public class ProductRepository : BaseRepository<Product>, IProductRepository
{
public ProductRepository(DbContext context) : base(context) { }
public async Task<IReadOnlyList<Product>> GetByCategoryAsync(int categoryId) =>
await FindAsync(p => p.CategoryId == categoryId);
public async Task<bool> ExistsByNameAsync(string name) =>
await ExistsAsync(p => p.Name == name);
}// Modern specification with primary constructor
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 with modern syntax
var spec = new ActiveProductsSpecification(new PaginationDto { PageIndex = 1, PageSize = 10 });
var products = await _repository.FindWithSpecificationAsync(spec);[HttpGet("{id}")]
public async Task<ApiResponse<ProductDto>> GetProduct(int id)
{
var result = await _productService.GetByIdAsync(id);
return result.Match(
success: product => ApiResponse<ProductDto>.Success(product.ToDto()),
failure: error => error.ToApiResponse<ProductDto>()
);
}// Modern domain event with record
public record ProductCreatedEvent(int ProductId, string ProductName, DateTime OccurredOn) : IDomainEvent
{
public ProductCreatedEvent(int productId, string productName) : this(productId, productName, DateTime.UtcNow) { }
}
// Modern entity with domain events
public class Product : BaseEntity
{
public void MarkAsCreated() =>
AddDomainEvent(new ProductCreatedEvent(Id, Name));
}// High-performance bulk operations
await repository.BulkInsertAsync(products);
await repository.BulkUpdateAsync(p => p.CategoryId == 1, p => p.Status, "Active");
await repository.BulkDeleteAsync(p => p.CreatedAt < DateTime.UtcNow.AddDays(-30));
// Modern projections for efficient data transfer
var summaries = await repository.GetPagedProjectionAsync(
pagination,
p => new ProductSummary(p.Id, p.Name, p.Price),
p => p.IsActive
);// Memory-efficient processing with async streaming
await foreach (var product in repository.FindAsyncEnumerable(p => p.IsActive))
{
await ProcessProductAsync(product);
}// Enterprise-optimized JSON with source generation
var json = myObject.SerializeModern();
var obj = jsonString.DeserializeModern<MyType>();
var clone = myObject.CloneViaJson();
// Modern JSON options for different scenarios
var options = JsonExtensions.DefaultOptions; // Production
var prettyOptions = JsonExtensions.PrettyOptions; // Development
var strictOptions = JsonExtensions.StrictOptions; // APIs// Modern validation with pattern matching
var validationResult = input switch
{
{ Length: 0 } => DomainError.Validation("EMPTY_INPUT", "Input cannot be empty"),
{ Length: > 100 } => DomainError.Validation("TOO_LONG", "Input too long"),
_ => null
};
// Modern JSON validation
if (!DataValidation.IsValidJson(jsonContent))
{
return DomainError.Validation("INVALID_JSON", "Invalid JSON format");
}Entity<TId> - Modern base entity with domain eventsBaseEntity - Modern base for int-keyed entities with audit trailIAuditableEntity - Interface for audit trail supportIEntityWithDomainEvents - Interface for domain event supportApiResponse<T> - Modern API response format with record structsPaginationDto - Modern pagination with search and filteringPagedResult<T> - Modern paginated results with metadataApiError - Modern error information with record structsDomainError - Modern business logic errors with HTTP mappingResult<T> - Modern functional result pattern with record structsErrorType - Modern error type categorizationErrorTypeExtensions - Modern error type utilitiesIRepository<TEntity> - Modern comprehensive repository interfaceISpecification<T> - Modern query specification patternBaseSpecification<T> - Modern base class for specificationsPagedResult<T> - Modern paginated query results[] syntax for modern collection initializationrequired keywordIAsyncEnumerable<T>[] syntax for efficient initializationrequired keywordswitch expressions and is patternsIAsyncEnumerable<T>We welcome contributions! Please see our Contributing Guidelines for details.
git clone https://github.com/Acontplus-S-A-S/acontplus-dotnet-libs.git
cd acontplus-dotnet-libs
dotnet restore
dotnet buildThis project is licensed under the MIT License - see the LICENSE file for details.
Ivan Paz - @iferpaz7
Acontplus S.A.S. - Enterprise software solutions
Built with ❤️ for the .NET community using the latest .NET 9 features