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
<PackageReference Include="alaasmagi.Base.Message" Version="1.8.0" />
<PackageVersion Include="alaasmagi.Base.Message" Version="1.8.0" />
<PackageReference Include="alaasmagi.Base.Message" />
paket add alaasmagi.Base.Message --version 1.8.0
#r "nuget: alaasmagi.Base.Message, 1.8.0"
#:package alaasmagi.Base.Message@1.8.0
#addin nuget:?package=alaasmagi.Base.Message&version=1.8.0
#tool nuget:?package=alaasmagi.Base.Message&version=1.8.0
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.Domainalaasmagi.Base.Domainalaasmagi.Base.Domain.Identityalaasmagi.Base.Contracts.DTOalaasmagi.Base.DTOalaasmagi.Base.Contracts.DataAccessalaasmagi.Base.DataAccess.EFalaasmagi.Base.Contracts.Applicationalaasmagi.Base.Applicationalaasmagi.Base.Contracts.Exceptionalaasmagi.Base.Exceptionalaasmagi.Base.Contracts.Cachealaasmagi.Base.Cachealaasmagi.Base.Contracts.Messagealaasmagi.Base.Messagealaasmagi.Base.Message.RabbitMQalaasmagi.Base.Keycloakalaasmagi.Base.Contracts.Authorizationalaasmagi.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>IBaseEntityMetaIBaseEntitySoftDeleteIBaseEntityUserId<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>ErrorError<TCode>ErrorDefaults
alaasmagi.Base.Contracts.DataAccess
Defines:
IBaseRepository<TEntity, TResourceKey, TActor>IBaseRepositorySoftDelete<TEntity, TResourceKey, TActor>IBaseUow(SaveChangesAsync, andTrySaveChangesAsyncwhich returns rejected writes as a failedIMethodResponse<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:
BaseExceptionBaseException<TCode>HttpExceptionHttpException<TCode>
alaasmagi.Base.Contracts.Cache
Defines:
IBaseCacheIBaseCacheResult<TValue>IBaseCacheEntryOptionsIBaseCacheSerializerIBaseCacheKeyBuilder
alaasmagi.Base.Cache
Provides:
BaseCacheBaseCacheResult<TValue>BaseCacheEntryOptionsBaseCacheOptionsBaseCacheKeyBuilderBaseJsonCacheSerializer
alaasmagi.Base.Contracts.Message
Defines:
IBaseEventEnvelope<TContent>IBaseEventPublisherPublishResultIBaseEventHandler<TContent>IBaseEventDispatcher<TContent>MessageDelivery,MessageDisposition
alaasmagi.Base.Contracts.Keycloak
Defines the Keycloak service and data abstractions:
IKeycloakAdminClientIKeycloakUser,IKeycloakRole
alaasmagi.Base.Message
Provides:
BaseEventEnvelope<TContent>(withBaseEventEnvelope<TContent>.Create(...)factory)DefaultSourcesBaseRoutingKey
alaasmagi.Base.Message.RabbitMQ
Provides:
RabbitMqOptionsRabbitMqConnectionManagerRabbitMqEventPublisherRabbitMqConsumerBase<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;Requeueis nacked after the overridableRequeueDelay, default 5 seconds)RabbitMqRoutingConsumerandRabbitMqEventRouter(one queue per service: routes each message by routing-key source/action to a typedIBaseEventHandler<TContent>, registered withAddRabbitMqRoutingConsumer)- 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}.rolesvalues in{module}.{action}form (exactly one dot) becomepermissionclaims; 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 toClientId), lifetime withClockSkew(default 30 seconds) - Keycloak admin API options and a typed
IKeycloakAdminClientimplementation KeycloakUserandKeycloakRoleadmin 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,Idfromsub,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 appsRequirePermissionAttribute([RequirePermission("courses", Actions.Create)]or[RequirePermission("courses.create")])PermissionPolicyProviderforperm:{module}.{action}policiesRequirePermission(module, action)for minimal API endpoints and groupsCurrentUser, registered as scopedICurrentUserAddPermissionAuthorization(options => ...)with a deny-by-default fallback policy and optionalValidateEndpointsOnStartup
Typical Usage
A common setup looks like this:
- Inherit from a
Base.Domainentity type that matches your needs. - Implement an
IMapperbetween your domain model and EF model if those types differ. - Inherit from
BaseRepository<...>orBaseRepositorySoftDelete<...>. - If your application layer uses different models, implement another mapper between application and domain models.
- Inherit from
BaseService<...>orBaseServiceSoftDelete<...>.
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.OpenIdConnectMicrosoft.AspNetCore.AuthenticationMicrosoft.AspNetCore.Authentication.JwtBearerMicrosoft.AspNetCore.Authentication.OpenIdConnectMicrosoft.AspNetCore.Identity.EntityFrameworkCoreMicrosoft.EntityFrameworkCoreMicrosoft.Extensions.DependencyInjectionMicrosoft.Extensions.HostingMicrosoft.Extensions.LoggingRabbitMQ.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.EFis 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.
- GitHub profile: alaasmagi
- LinkedIn profile: alaasmagi
- Email: aleksander.laasmagi@gmail.com
- Repository: base-nuget
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.eventsand notification commands tonotification-hub.commands. Both are durable topic exchanges in vhost/, managed externally. ConfigureRabbitMqOptions.Exchange; the packages do not declare exchanges or queues. - Use
DefaultSources.IdentityHubfor Keycloak andDefaultSources.NotificationHubfor 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), andTimeZone(IANA, e.g.Europe/Tallinn). Publish one command per recipient. Event content does not inherit this base. LocaleandTimeZoneretain 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,contentVersionandcontent. Create both withBaseEventEnvelope<T>.Create(...); whether a message is an event or a command is decided by the exchange it is published on. There is no envelopeexpiresAt. - No envelope field is ever
null;contentis an object ({}when there is nothing to send). The envelope converter and the publisher reject a missing ornullfield, and consumers reject such a message instead of handling it. Unknown fields are ignored. content.expiresAtandvalidForMinutesare display data for notification emails. Content that shows a validity time implementsIExpiringNotificationContent. Broker TTL remains a separate transport option.- Keycloak commands are
email-user-verify(VerifyEmailContent),email-user-2fa-otp(OtpEmailContent) andemail-user-password-reset(PasswordResetContent).UserEventContentcarriesuserId,email,username,fullName,localeandtimeZone, and omits absent optional properties;user-deletedcarries onlyuserId. - Send integer fields (
validForMinutes,fractions) as JSON numbers, money as invariant decimal strings with a separate currency, dates asyyyy-MM-dd, and times of day asHH: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 | Versions 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. |
-
net10.0
- alaasmagi.Base.Contracts.Message (>= 1.8.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.9)
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 |