Hasim.Infrastructure 0.1.2

dotnet add package Hasim.Infrastructure --version 0.1.2
                    
NuGet\Install-Package Hasim.Infrastructure -Version 0.1.2
                    
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="Hasim.Infrastructure" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hasim.Infrastructure" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Hasim.Infrastructure" />
                    
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 Hasim.Infrastructure --version 0.1.2
                    
#r "nuget: Hasim.Infrastructure, 0.1.2"
                    
#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 Hasim.Infrastructure@0.1.2
                    
#: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=Hasim.Infrastructure&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Hasim.Infrastructure&version=0.1.2
                    
Install as a Cake Tool

Hasim.Infrastructure

.NET NuGet NuGet Downloads Build License: MIT

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 repositoryIEntityRepository<TEntity, TKey> / EntityRepository<TEntity, TKey> with async CRUD and query helpers, soft-delete aware.
  • Unit of workUnitOfWork that applies auditable timestamps, soft delete, and delegates audit creation.
  • DI moduleInfrastructureModule registers the repository via an open-generic AddScoped.
  • 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

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request.

📄 License

This project is licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.2 112 8/11/2026
0.1.1 111 8/2/2026
0.1.0 116 8/2/2026