Hasim 0.1.3

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

Hasim

.NET NuGet NuGet Downloads Build License: MIT

A lightweight .NET 8 foundation for ASP.NET Core applications, providing reusable base types and common abstractions for modern .NET apps.

Built to sit alongside the Hasim.* ecosystem (Hasim.Core, Hasim.EntityFrameworkCore, Hasim.Auditify, Hasim.Injectify), this library ships a dispose-pattern base type (IDisposable + IAsyncDisposable) and a current-user abstraction that reads the authenticated ClaimsPrincipal from IHttpContextAccessor — small, focused building blocks for your web app.

✨ Features

  • Disposable base typeDisposable implements the standard dispose pattern with a finalizer, GC.SuppressFinalize, and virtual synchronous (DisposeCore) / asynchronous (DisposeAsyncCore) hooks.
  • Current-user abstractionICurrentUser / CurrentUser resolve the authenticated user's id, name, email and authentication state without touching HttpContext directly.
  • Packaged as a NuGet library — drop it into any ASP.NET Core app.
  • Mapping contractsIMapTo<TDestination> and IMapFrom<TSource> define manual mapping contracts between objects.

📦 Installation

dotnet add package Hasim

🚀 Getting Started

1. Register the services

Register IHttpContextAccessor and the current-user services with your DI container (e.g. in Program.cs):

builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<ICurrentUser, CurrentUser>();

2. Use the current user

Inject ICurrentUser into your components or services and inspect the authenticated principal:

using Hasim.Services;

public class MyComponent(ICurrentUser user)
{
    public string? DisplayName => user.UserName;
    public string? Email => user.Email;
    public int? Id => user.AsIntegerReadId;
    public bool Authenticated => user.IsAuthenticated;
}

3. Derive from Disposable

Create a disposable service by extending Hasim.Common.Disposable and overriding the dispose hooks you need:

using Hasim.Common;

public class MyService : Disposable
{
    protected override void DisposeCore() => /* release unmanaged/synchronous resources */;

    protected override async ValueTask DisposeAsyncCore()
    {
        // release async resources, then call DisposeCore() via base
        await base.DisposeAsyncCore();
    }
}

4. Use the mapping contracts

Implement IMapTo<TDestination> to map the current object to another type, and IMapFrom<TSource> to map from a source object to the current type:

using Hasim.Mapping;

public class UserDto : IMapFrom<User>
{
    public Guid Id { get; set; }
    public string FullName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;

    public void MapFrom(User source)
    {
        Id = source.Id;
        FullName = $"{source.FirstName} {source.LastName}";
        Email = source.Email;
    }
}

public class CreateUserDto : IMapTo<User>
{
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;

    public User MapTo()
    {
        return new User
        {
            FirstName = FirstName,
            LastName = LastName,
            Email = Email
        };
    }
}

public class User
{
    public Guid Id { get; set; }
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
}

🧱 Architecture

Hasim/
└── Src/Hasim/
    ├── Common/
    │   └── Disposable.cs       # IDisposable + IAsyncDisposable base type
    ├── Mapping/
    │   ├── MapFrom.cs          # IMapFrom<TSource> interface
    │   └── MapTo.cs            # IMapTo<TDestination> interface
    └── Services/
        └── CurrentUser.cs      # ICurrentUser interface + CurrentUser implementation

CurrentUser members

Member Description
Id Current user's unique identifier as a Guid?, or null when absent or invalid.
AsIntegerId Id as an int (0 when unavailable).
AsIntegerReadId Id as an int? (null when unavailable).
AsStringId Id as a string (string.Empty when unavailable).
UserName Current user's display name, or null.
Email Current user's email address, or null.
IsAuthenticated Whether the current user is authenticated.

📚 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 (2)

Showing the top 2 NuGet packages that depend on Hasim:

Package Downloads
Hasim.Auditify

A lightweight, pluggable audit-trail library for EF Core 8+. Automatically captures entity changes (Added/Modified/Deleted), supports sensitive data masking, soft-delete patterns, and timestamp tracking.

Hasim.Infrastructure

Todo Description.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 181 8/11/2026
0.1.2 156 8/1/2026
0.1.1 88 8/1/2026
0.1.0 227 7/30/2026