alaasmagi.Base.Message 1.8.0

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

alaasmagi Base Packages

Reusable base-layer building blocks for .NET applications.

This package set provides shared contracts and generic implementations for common layers:

  • alaasmagi.Base.Contracts.Domain
  • alaasmagi.Base.Domain
  • alaasmagi.Base.Domain.Identity
  • alaasmagi.Base.Contracts.DTO
  • alaasmagi.Base.DTO
  • alaasmagi.Base.Contracts.DataAccess
  • alaasmagi.Base.DataAccess.EF
  • alaasmagi.Base.Contracts.Application
  • alaasmagi.Base.Application
  • alaasmagi.Base.Contracts.Exception
  • alaasmagi.Base.Exception
  • alaasmagi.Base.Contracts.Cache
  • alaasmagi.Base.Cache
  • alaasmagi.Base.Contracts.Message
  • alaasmagi.Base.Message
  • alaasmagi.Base.Message.RabbitMQ
  • alaasmagi.Base.Keycloak
  • alaasmagi.Base.Contracts.Authorization
  • alaasmagi.Base.Authorization

Included Capabilities

These packages cover the common building blocks used across layered applications:

  • strongly typed base entity contracts
  • domain base classes with metadata, ownership, and soft delete support
  • mapper abstractions between layers
  • method-response and error models
  • generic repository contracts
  • generic EF Core repository implementations
  • unit-of-work abstractions
  • generic application service contracts and implementations
  • typed base exceptions and HTTP exceptions
  • key-value cache contracts and provider-neutral base implementations
  • event-envelope, publisher, and handler contracts
  • RabbitMQ event publishing and listener infrastructure
  • Keycloak authentication helpers, admin API models, and identity event payloads
  • permission-based authorization with deny-by-default endpoints

Package Overview

alaasmagi.Base.Contracts.Domain

Defines contracts such as:

  • IBaseEntity<TKey>
  • IBaseEntityMeta
  • IBaseEntitySoftDelete
  • IBaseEntityUserId<TKey>
  • IBaseEntityWithMeta<TKey>
  • IBaseEntityWithMetaSoftDelete<TKey>

alaasmagi.Base.Domain

Provides reusable base entity types such as:

  • BaseEntity<TKey>
  • BaseEntityWithMeta<TKey>
  • BaseEntityWithMetaSoftDelete<TKey>
  • BaseEntityUser<TKey>
  • BaseEntityUserWithMeta<TKey, TUserKey>
  • BaseEntityUserWithMetaSoftDelete<TKey, TUserKey>

alaasmagi.Base.Domain.Identity

Provides ASP.NET Core Identity base types such as:

  • BaseIdentityUser<TKey>
  • BaseIdentityUserWithMeta<TKey>
  • BaseIdentityUserWithMetaSoftDelete<TKey>
  • BaseIdentityUserWithMetaSoftDeleteConcurrency<TKey>
  • BaseIdentityRole<TKey>
  • BaseIdentityRoleWithMeta<TKey>
  • BaseIdentityRoleWithMetaSoftDelete<TKey>
  • BaseIdentityRoleWithMetaSoftDeleteConcurrency<TKey>

alaasmagi.Base.Contracts.DTO

Defines:

  • IMapper<TUpperEntity, TLowerEntity, TKey>
  • IMethodResponse<TValue>
  • IError<TCode>

alaasmagi.Base.DTO

Provides:

  • MethodResponse<TValue>
  • MethodResponse<TValue, TError>
  • Error
  • Error<TCode>
  • ErrorDefaults

alaasmagi.Base.Contracts.DataAccess

Defines:

  • IBaseRepository<TEntity, TResourceKey, TActor>
  • IBaseRepositorySoftDelete<TEntity, TResourceKey, TActor>
  • IBaseUow (SaveChangesAsync, and TrySaveChangesAsync which returns rejected writes as a failed IMethodResponse<int>)

alaasmagi.Base.DataAccess.EF

Provides EF Core implementations such as:

  • BaseRepository<TDomainEntity, TDataAccessEntity, TMapper, TResourceKey, TActor>
  • BaseRepositorySoftDelete<TDomainEntity, TDataAccessEntity, TMapper, TResourceKey, TActor>
  • BaseUow<TDbContext>

alaasmagi.Base.Contracts.Application

Defines:

  • IBaseService<TEntity, TKey, TActor>
  • IBaseServiceSoftDelete<TEntity, TKey, TActor>
  • IBaseServiceUow

alaasmagi.Base.Application

Provides:

  • BaseService<TEntity, TDomainEntity, TRepository, TKey, TActor>
  • BaseServiceSoftDelete<TEntity, TDomainEntity, TRepository, TKey, TActor>
  • BaseServiceUow<TUow>

alaasmagi.Base.Contracts.Exception

Defines:

  • IBaseException<TCode>
  • IHttpException<TCode>

alaasmagi.Base.Exception

Provides:

  • BaseException
  • BaseException<TCode>
  • HttpException
  • HttpException<TCode>

alaasmagi.Base.Contracts.Cache

Defines:

  • IBaseCache
  • IBaseCacheResult<TValue>
  • IBaseCacheEntryOptions
  • IBaseCacheSerializer
  • IBaseCacheKeyBuilder

alaasmagi.Base.Cache

Provides:

  • BaseCache
  • BaseCacheResult<TValue>
  • BaseCacheEntryOptions
  • BaseCacheOptions
  • BaseCacheKeyBuilder
  • BaseJsonCacheSerializer

alaasmagi.Base.Contracts.Message

Defines:

  • IBaseEventEnvelope<TContent>
  • IBaseEventPublisher
  • PublishResult
  • IBaseEventHandler<TContent>
  • IBaseEventDispatcher<TContent>
  • MessageDelivery, MessageDisposition

alaasmagi.Base.Contracts.Keycloak

Defines the Keycloak service and data abstractions:

  • IKeycloakAdminClient
  • IKeycloakUser, IKeycloakRole

alaasmagi.Base.Message

Provides:

  • BaseEventEnvelope<TContent> (with BaseEventEnvelope<TContent>.Create(...) factory)
  • DefaultSources
  • BaseRoutingKey

alaasmagi.Base.Message.RabbitMQ

Provides:

  • RabbitMqOptions
  • RabbitMqConnectionManager
  • RabbitMqEventPublisher
  • RabbitMqConsumerBase<TContent> (acks when the handler returns; invalid envelopes and handler failures are rejected without requeue)
  • RabbitMqDeliveryConsumerBase<TContent> (typed envelope; the subclass returns ack, requeue or reject per message; invalid envelopes are rejected)
  • RabbitMqDeliveryConsumerBase (raw delivery with routing key; the handler decides ack, requeue or reject; Requeue is nacked after the overridable RequeueDelay, default 5 seconds)
  • RabbitMqRoutingConsumer and RabbitMqEventRouter (one queue per service: routes each message by routing-key source/action to a typed IBaseEventHandler<TContent>, registered with AddRabbitMqRoutingConsumer)
  • RabbitMQ publisher and consumer dependency injection helpers

alaasmagi.Base.Keycloak

Provides:

  • Keycloak JWT bearer authentication registration
  • Keycloak OpenID Connect authentication registration (configurable scopes, cookie paths, claim types and PAR), and JWT bearer as an extra scheme next to it
  • Keycloak permission mapping, always on for JWT bearer and OpenID Connect and the only claims transformation: resource_access.{own clientId}.roles values in {module}.{action} form (exactly one dot) become permission claims; role names and other clients' roles are ignored; in OIDC mode they come from the stored access token and are refreshed with it
  • raw claim names by default (KeycloakOptions.MapInboundClaims = false)
  • contract token validation: JWKS signature, exact issuer, audience (Audience, falling back to ClientId), lifetime with ClockSkew (default 30 seconds)
  • Keycloak admin API options and a typed IKeycloakAdminClient implementation
  • KeycloakUser and KeycloakRole admin models
  • identity event content payloads matching the message schema:
    • UserEventContent (user-created, user-deleted, user-updated, user-enabled, user-disabled)
    • VerifyEmailContent (email-user-verify)
    • OtpEmailContent (email-user-2fa-otp)
    • PasswordResetContent (email-user-password-reset)

alaasmagi.Base.Contracts.Authorization

Defines:

  • ICurrentUser (IsAuthenticated, Id from sub, Email, Name, IsService, ClientId, Permissions, HasPermission)

alaasmagi.Base.Authorization

Provides (reads permission claims only; no Keycloak dependency):

  • Actions (View, ViewAll, Create, Edit, Delete), extensible by apps
  • RequirePermissionAttribute ([RequirePermission("courses", Actions.Create)] or [RequirePermission("courses.create")])
  • PermissionPolicyProvider for perm:{module}.{action} policies
  • RequirePermission(module, action) for minimal API endpoints and groups
  • CurrentUser, registered as scoped ICurrentUser
  • AddPermissionAuthorization(options => ...) with a deny-by-default fallback policy and optional ValidateEndpointsOnStartup

Typical Usage

A common setup looks like this:

  1. Inherit from a Base.Domain entity type that matches your needs.
  2. Implement an IMapper between your domain model and EF model if those types differ.
  3. Inherit from BaseRepository<...> or BaseRepositorySoftDelete<...>.
  4. If your application layer uses different models, implement another mapper between application and domain models.
  5. Inherit from BaseService<...> or BaseServiceSoftDelete<...>.

Example

using Base.Contracts.DTO;
using Base.DataAccess.EF;
using Base.Domain;
using Microsoft.EntityFrameworkCore;

public class Todo : BaseEntityWithMetaSoftDelete<Guid>
{
    public string Title { get; set; } = default!;
}

public class TodoDbEntity : BaseEntityWithMetaSoftDelete<Guid>
{
    public string Title { get; set; } = default!;
}

public class TodoMapper : IMapper<Todo, TodoDbEntity, Guid>
{
    public Todo? Map(TodoDbEntity? entity) => entity == null
        ? null
        : new Todo
        {
            Id = entity.Id,
            Title = entity.Title,
            CreatedAt = entity.CreatedAt,
            CreatedBy = entity.CreatedBy,
            UpdatedAt = entity.UpdatedAt,
            UpdatedBy = entity.UpdatedBy,
            IsDeleted = entity.IsDeleted
        };

    public IEnumerable<Todo>? Map(IEnumerable<TodoDbEntity>? entities) =>
        entities?.Select(Map)!;

    public TodoDbEntity? Map(Todo? entity) => entity == null
        ? null
        : new TodoDbEntity
        {
            Id = entity.Id,
            Title = entity.Title,
            CreatedAt = entity.CreatedAt,
            CreatedBy = entity.CreatedBy,
            UpdatedAt = entity.UpdatedAt,
            UpdatedBy = entity.UpdatedBy,
            IsDeleted = entity.IsDeleted
        };

    public IEnumerable<TodoDbEntity>? Map(IEnumerable<Todo>? entities) =>
        entities?.Select(Map)!;
}

public class TodoRepository
    : BaseRepositorySoftDelete<Todo, TodoDbEntity, TodoMapper, Guid, Guid>
{
    public TodoRepository(DbContext dbContext, TodoMapper mapper)
        : base(dbContext, mapper)
    {
    }
}

Framework and Dependencies

All packages in this repository currently target:

  • .NET 10.0

All package projects currently declare:

  • version 1.8.0

Relevant package dependencies used across the set include:

  • Duende.AccessTokenManagement.OpenIdConnect
  • Microsoft.AspNetCore.Authentication
  • Microsoft.AspNetCore.Authentication.JwtBearer
  • Microsoft.AspNetCore.Authentication.OpenIdConnect
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore
  • Microsoft.Extensions.DependencyInjection
  • Microsoft.Extensions.Hosting
  • Microsoft.Extensions.Logging
  • RabbitMQ.Client

Notes

  • These packages are designed to be used together, but each package can also be consumed independently where appropriate.
  • Keep package versions in sync across the alaasmagi.Base.* set.
  • Base.DataAccess.EF is intended for EF Core based persistence.
  • Repository and service methods return IMethodResponse<T> so calling code can handle success and failure consistently.
  • Metadata timestamps and actor fields are populated automatically by the EF repository base classes when supported by the entity type.
  • User-based scoping is applied automatically when the entity implements IBaseEntityUserId<TActor> and a non-default actor value is supplied.
  • Cache packages provide string-keyed, typed value abstractions that can be backed by Redis or another key-value cache store.
  • Message packages use the platform event envelope (id, source, tenant, action, timestamp, contentVersion, content) for events and commands alike; no field is ever null. Routing segments must be non-empty and contain no dots.
  • Keycloak helpers cover authentication registration, permission claim mapping, admin user operations, and identity email/lifecycle event payloads.
  • Authorization helpers check permissions only, never roles. Endpoints without RequirePermission, [Authorize], or [AllowAnonymous] are denied.

Developer

Developed and maintained by Aleksander Laasmägi.

Platform notification contract

The authoritative examples are in docs/contracts/event-contract.md. Values in square brackets are placeholders, not literal wire values. Use contentVersion: "1.0".

  • Publish domain events to identity-hub.events and notification commands to notification-hub.commands. Both are durable topic exchanges in vhost /, managed externally. Configure RabbitMqOptions.Exchange; the packages do not declare exchanges or queues.
  • Use DefaultSources.IdentityHub for Keycloak and DefaultSources.NotificationHub for the notification service. Apps use their existing slug for both source and tenant; Keycloak uses the realm as tenant.
  • Derive routing keys only through BaseRoutingKey.For(envelope). Routing keys never belong in the body.
  • Command content inherits BaseNotificationContent: UserId (UUID string), Email, FullName, Locale (BCP 47 including region, e.g. et-EE), and TimeZone (IANA, e.g. Europe/Tallinn). Publish one command per recipient. Event content does not inherit this base.
  • Locale and TimeZone retain nullable setters for source compatibility, but both must be populated for commands. The RabbitMQ publisher validates recipient metadata before contacting the broker.
  • Events and commands share one envelope with exactly id, source, tenant, action, timestamp, contentVersion and content. Create both with BaseEventEnvelope<T>.Create(...); whether a message is an event or a command is decided by the exchange it is published on. There is no envelope expiresAt.
  • No envelope field is ever null; content is an object ({} when there is nothing to send). The envelope converter and the publisher reject a missing or null field, and consumers reject such a message instead of handling it. Unknown fields are ignored.
  • content.expiresAt and validForMinutes are display data for notification emails. Content that shows a validity time implements IExpiringNotificationContent. Broker TTL remains a separate transport option.
  • Keycloak commands are email-user-verify (VerifyEmailContent), email-user-2fa-otp (OtpEmailContent) and email-user-password-reset (PasswordResetContent). UserEventContent carries userId, email, username, fullName, locale and timeZone, and omits absent optional properties; user-deleted carries only userId.
  • Send integer fields (validForMinutes, fractions) as JSON numbers, money as invariant decimal strings with a separate currency, dates as yyyy-MM-dd, and times of day as HH:mm.
  • Never log or persist notification content such as OTP codes or action links.

Run contract tests with dotnet test tests/Base.Message.Tests/Base.Message.Tests.csproj -c Release.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 alaasmagi.Base.Message:

Package Downloads
alaasmagi.Base.Keycloak

Base Keycloak package for .NET webapps

alaasmagi.Base.Message.RabbitMQ

Base Message RabbitMQ package for .NET webapps

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.0 66 11/19/2026
1.7.0 74 11/18/2026
1.6.1 106 11/11/2026
1.6.0 107 11/11/2026
1.5.0 123 10/30/2026
1.4.0 120 10/27/2026
1.3.1 118 10/26/2026
1.3.0 206 7/31/2026
1.2.0 148 7/30/2026
1.1.9 166 7/10/2026
1.1.8 143 7/10/2026
1.1.7 152 7/9/2026
1.1.6 132 7/5/2026
1.1.4 129 7/5/2026