Hasim.Infrastructure
0.1.2
dotnet add package Hasim.Infrastructure --version 0.1.2
NuGet\Install-Package Hasim.Infrastructure -Version 0.1.2
<PackageReference Include="Hasim.Infrastructure" Version="0.1.2" />
<PackageVersion Include="Hasim.Infrastructure" Version="0.1.2" />
<PackageReference Include="Hasim.Infrastructure" />
paket add Hasim.Infrastructure --version 0.1.2
#r "nuget: Hasim.Infrastructure, 0.1.2"
#:package Hasim.Infrastructure@0.1.2
#addin nuget:?package=Hasim.Infrastructure&version=0.1.2
#tool nuget:?package=Hasim.Infrastructure&version=0.1.2
Hasim.Infrastructure
A .NET 8 class library providing shared infrastructure building blocks — a generic EF Core repository, a unit of work, and DI registration — to accelerate .NET application development across the Hasim.* ecosystem.
This repository holds the reusable infrastructure services and helpers consumed by the application projects. It is published as a NuGet package (Hasim.Infrastructure) and referenced wherever cross-cutting infrastructure is needed.
✨ Features
- Generic EF Core repository —
IEntityRepository<TEntity, TKey>/EntityRepository<TEntity, TKey>with async CRUD and query helpers, soft-delete aware. - Unit of work —
UnitOfWorkthat applies auditable timestamps, soft delete, and delegates audit creation. - DI module —
InfrastructureModuleregisters the repository via an open-genericAddScoped. - Packaged as a NuGet library — one shared infrastructure dependency for your whole ecosystem.
📦 Installation
dotnet add package Hasim.Infrastructure
🚀 Getting Started
Hasim.Infrastructure is the infrastructure layer. Reference it from your application projects and use its services through dependency injection.
1. Add the package
dotnet add package Hasim.Infrastructure
2. Reference the infrastructure layer
Add a package reference from your application project to Hasim.Infrastructure.
3. Use the repository in a service
The repository stages changes; the service persists them via the unit of work or context:
using Hasim.Infrastructure.Contracts;
public class DriverService
{
private readonly IEntityRepository<Driver, int> _repository;
public DriverService(IEntityRepository<Driver, int> repository)
{
_repository = repository;
}
public async Task<Driver?> GetDriverAsync(int id) => await _repository.FindByIdAsync(id);
}
Register it with the InfrastructureModule, or manually:
services.AddScoped(typeof(IEntityRepository<,>), typeof(EntityRepository<,>));
Transactions with ExecutionStrategy
For operations that require multiple repository calls within a transaction, use ExecutionStrategy to enable automatic retries on transient errors:
using Hasim.Infrastructure.Contracts;
public class UserService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IUserRepository _userRepository;
private readonly IRoleRepository _roleRepository;
public UserService(
IUnitOfWork unitOfWork,
IUserRepository userRepository,
IRoleRepository roleRepository)
{
_unitOfWork = unitOfWork;
_userRepository = userRepository;
_roleRepository = roleRepository;
}
public async Task CreateUserAsync(
CreateUserRequest request,
CancellationToken cancellationToken = default)
{
var strategy = _unitOfWork.CreateExecutionStrategy();
await strategy.ExecuteAsync(async () =>
{
await using var transaction = await _unitOfWork.BeginTransactionAsync();
try
{
var user = new User
{
Id = Guid.NewGuid(),
Email = request.Email,
Name = request.Name
};
await _userRepository.AddAsync(user);
var role = await _roleRepository.GetByNameAsync("User", cancellationToken);
user.RoleId = role.Id;
await _unitOfWork.AutomaticSavingAsync(cancellationToken);
await _unitOfWork.CommitAsync();
}
catch
{
await transaction.RollbackAsync();
throw;
}
});
}
}
Flow:
CreateUserAsync()
│
▼
CreateExecutionStrategy()
│
▼
ExecuteAsync()
│
▼
BeginTransactionAsync()
│
├── Add User
│
├── Add/Update Role
│
├── AutomaticSavingAsync()
│
▼
CommitAsync()
│
▼
OK
If a transient error occurs, for example a temporary SQL Server outage:
ExecutionStrategy
│
├── Attempt 1
│ └── transient error
│
├── Attempt 2
│ └── transient error
│
└── Attempt 3
└── OK
🧱 Architecture
Hasim.Infrastructure/
├── Hasim.Infrastructure.sln
├── Src/
│ ├── Hasim.Infrastructure/ # the class library (net8.0)
│ │ ├── Contracts/ # IEntityRepository, EntityRepository
│ │ ├── Configurations/ # UnitOfWork, IUnitOfWork
│ │ └── Modules/ # InfrastructureModule (DI registration)
│ └── Hasim.Infrastructure.UnitTests/ # xUnit tests
└── assets/images/Logo.png # package icon
Components
| Component | Description |
|---|---|
IEntityRepository<TEntity, TKey> |
Contract for the generic repository. |
EntityRepository<TEntity, TKey> |
Generic repository over AuditIdentityContext — stages CRUD; soft-deletes ISoftDelete entities. |
UnitOfWork / IUnitOfWork |
Coordinates saving, auditable timestamps, soft delete and audit logging. |
InfrastructureModule |
BaseInjectifyModule that registers the repository in DI. |
📚 Dependencies
🔧 Requirements
- .NET 8.0 SDK
🤝 Contributing
- Fork the repository.
- Create a feature branch.
- Submit a pull request.
📄 License
This project is licensed under the MIT License.
| 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. |
-
net8.0
- Hasim (>= 0.1.2)
- Hasim.Auditify (>= 0.1.5)
- Hasim.EntityFrameworkCore (>= 0.1.1)
- Hasim.Injectify (>= 0.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.