BaseShared 1.2.1

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

BaseShared

Shared building blocks for .NET solutions. This package provides reusable domain primitives, CQRS abstractions, result pattern, validation helpers, specification pattern, repository and unit-of-work abstractions, and supporting utilities that can be used in any domain.

Contents

  • Domain base types
    • BaseEntity, AggregateRoot, ValueObject
    • Domain event interfaces and base classes (IDomainEvent, BaseDomainEvent, IDomainEventHandler)
    • IDateTime abstraction for testable time access
  • Result pattern
    • Result, Error, ValidationError, ErrorType, CommonErrors
    • Extensions to convert results to API responses (ApiResponse, ResultToResponseMapper)
  • CQRS abstractions
    • ICommand, ICommandHandler<TCommand>
    • IQuery<TResult>, IQueryHandler<TQuery, TResult>
  • Repository and Unit of Work
    • Generic repository interface IRepository<T> for aggregate roots
    • Unit of work abstraction IUnitOfWork and error definitions UnitOfWorkErrors
  • Specification pattern
    • ISpecification<T>, BaseSpecification<T>
    • SpecificationExtensions for combining and applying specifications
  • Validation helpers
    • CommonRegularExpressions, CommonValidationErrors
    • Validation extensions for primitives, enums, dates and pagination
  • Common utilities
    • PaginatedResult<T> and PaginationExtensions
    • ChangeWrapper<T> for tracking value changes
    • IDomainService marker interface
    • Date/time extensions (DateTimeExtensions)
    • Time zone support via IANATimeZone
  • Email models
    • EmailAddress, EmailAttachment, EmailMessage, EmailSendResult

Installation

After you have added the package source (local feed, private feed, or nuget.org), install the package into your project:

dotnet add package BaseShared --version 1.2.1

Or use the Manage NuGet Packages UI in Visual Studio and search for BaseShared.

Basic usage

Working with the Result pattern

using Meta.Shared.ResultPattern;

public async Task<Result<User>> RegisterUserAsync(RegisterUserCommand command)
{
    if (await _userRepository.ExistsAsync(command.Email))
    {
        return Result.Failure<User>(CommonErrors.Conflict("User with this email already exists."));
    }

    var user = new User(command.Email, command.Name);
    await _userRepository.AddAsync(user);

    return Result.Success(user);
}

CQRS handlers

using Meta.Shared.CQRS;
using Meta.Shared.ResultPattern;

public sealed record GetUserByIdQuery(Guid Id) : IQuery<Result<UserDto>>;

public sealed class GetUserByIdQueryHandler
    : IQueryHandler<GetUserByIdQuery, Result<UserDto>>
{
    private readonly IUserReadRepository _users;

    public GetUserByIdQueryHandler(IUserReadRepository users) => _users = users;

    public async Task<Result<UserDto>> Handle(GetUserByIdQuery query, CancellationToken cancellationToken)
    {
        var user = await _users.GetByIdAsync(query.Id, cancellationToken);
        if (user is null)
        {
            return Result.Failure<UserDto>(CommonErrors.NotFound("User"));
        }

        return Result.Success(new UserDto(user.Id, user.Email, user.Name));
    }
}

Specifications and repositories

using Meta.Shared.RepositoryPattern;
using Meta.Shared.SpecificationPattern.Core;

public sealed class ActiveUsersSpecification : BaseSpecification<User>
{
    public ActiveUsersSpecification()
    {
        AddCriteria(u => u.IsActive);
        AddOrderBy(u => u.CreatedOnUtc);
    }
}

public async Task<IReadOnlyList<User>> GetActiveUsersAsync(IRepository<User> repository)
{
    var spec = new ActiveUsersSpecification();
    return await repository.ListAsync(spec);
}

Domain base classes

using Meta.Shared.Common;
using Meta.Shared.Common.DomainEvents;

public sealed class User : AggregateRoot<Guid>
{
    // Value object and properties omitted for brevity

    public void Activate()
    {
        // business rules...
        AddDomainEvent(new UserActivatedDomainEvent(Id));
    }
}

public sealed record UserActivatedDomainEvent(Guid UserId) : BaseDomainEvent;

How to use this package in new solutions

  1. Add the package source
  • Point NuGet to your feed that contains BaseShared.1.2.1.nupkg (local folder, Azure Artifacts, GitHub Packages, or nuget.org).
  1. Install the package
  • Add BaseShared to your application, API, or infrastructure projects.
  1. Adopt the patterns
  • Use the provided domain base classes for new aggregates and entities.
  • Implement commands, queries and handlers using the CQRS interfaces.
  • Return Result/Result<T> from your application services and handlers.
  • Use repositories, unit of work and specifications to access your persistence layer.
  • Reuse validation helpers and common error definitions for consistent validation and error handling.
  1. Extend as needed
  • If your project requires additional shared primitives or patterns, add them to BaseShared and publish a new package version.

Target framework

BaseShared currently targets .NET 8.0 and .NET 9.0 (net8.0;net9.0). Consumer projects can target either framework (or compatible later frameworks).

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 is compatible.  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
1.2.1 64 3/19/2026
1.2.0 54 3/19/2026
1.1.0 61 3/4/2026
1.0.1 53 3/4/2026
1.0.0 56 3/4/2026