Skip to content

improvgroup/sharedcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

243 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shared Code

.NET License: MIT NuGet: SharedCode.Core NuGet: SharedCode.Data NuGet: SharedCode.Data.CosmosDb NuGet: SharedCode.Data.EntityFramework NuGet: SharedCode.DependencyInjection NuGet: SharedCode.MediatR NuGet: SharedCode.Web NuGet: SharedCode.Windows.WPF

A collection of reusable utility libraries for .NET, published as individual NuGet packages. Each package targets a specific concern — from core extensions and domain primitives to data access, dependency injection, MediatR pipelines, ASP.NET Core helpers, and WPF utilities — so you can pull in only what you need.


Table of Contents


Packages

Package NuGet Target Frameworks Description
SharedCode.Core NuGet netstandard2.0, netstandard2.1, net8.0, net9.0 Core utilities: extensions, specifications, domain primitives, security, threading, reactive
SharedCode.Data NuGet netstandard2.0, netstandard2.1, net8.0, net9.0 Framework-agnostic data access abstractions: repository pattern, paging, query results
SharedCode.Data.CosmosDb NuGet net8.0, net9.0 Azure Cosmos DB integration and helpers
SharedCode.Data.EntityFramework NuGet net8.0, net9.0 Entity Framework Core integration: auditable contexts, EF repository, specifications
SharedCode.DependencyInjection NuGet netstandard2.0, netstandard2.1, net8.0, net9.0 DI assembly scanning and auto-registration via IDependencyRegister
SharedCode.MediatR NuGet net8.0, net9.0 MediatR command/query abstractions and pipeline helpers
SharedCode.Web NuGet net9.0 ASP.NET Core helpers: base controller, resilient HTTP client setup, health checks
SharedCode.Windows.WPF NuGet net9.0-windows10.0.22621.0 WPF helpers: BindableBase, value converters, attached properties, MVVM mediator

Requirements

  • .NET 9 SDK (for net9.0 targets)
  • .NET 8 SDK (for net8.0 targets)
  • .NET Standard 2.0 / 2.1 targets are compatible with .NET Framework 4.6.1+ and .NET Core 2.0+

Installation

Install any package via the NuGet Package Manager, the .NET CLI, or by editing your project file.

.NET CLI

dotnet add package SharedCode.Core
dotnet add package SharedCode.Data
dotnet add package SharedCode.Data.CosmosDb
dotnet add package SharedCode.Data.EntityFramework
dotnet add package SharedCode.DependencyInjection
dotnet add package SharedCode.MediatR
dotnet add package SharedCode.Web
dotnet add package SharedCode.Windows.WPF

Package Manager Console

Install-Package SharedCode.Core
Install-Package SharedCode.Data
Install-Package SharedCode.Data.CosmosDb
Install-Package SharedCode.Data.EntityFramework
Install-Package SharedCode.DependencyInjection
Install-Package SharedCode.MediatR
Install-Package SharedCode.Web
Install-Package SharedCode.Windows.WPF

Package Details

SharedCode.Core

NuGet

Core utilities and domain primitives that are shared across all other packages. Targets netstandard2.0, netstandard2.1, net8.0, and net9.0.

Highlights

  • Extension methodsDateTime, DateTimeOffset, string, int, Enum, collections, Type, IEnumerable, reflection, and more
  • Specification pattern — strongly typed Specification<T> / Specification<T, TResult> with a fluent query builder (filter, ordering, paging, includes)
  • Domain primitivesValueObject, BaseException, result types (IResult, IErrorResult, ValidationErrorResult)
  • SecurityHasher utility supporting multiple hash algorithms
  • TextStringExtensions, StringBuilderExtensions, masking helpers
  • Calendar — business-day arithmetic, DateTimeFormat, DayOfWeekExtensions
  • Reactive — built on System.Reactive and System.Interactive
  • Threading — async-friendly utilities

Quick Start

// Add business days
var nextBusinessDay = DateTime.Today.AddBusinessDays(3);

// Specification pattern
public sealed class ActiveUsersSpec : Specification<User>
{
    public ActiveUsersSpec() =>
        this.Query.Where(u => u.IsActive).OrderBy(u => u.LastName);
}

SharedCode.Data

NuGet

Framework-agnostic data access abstractions. Targets netstandard2.0, netstandard2.1, net8.0, and net9.0.

Highlights

  • IQueryRepository<T> / ICommandRepository<T> contracts
  • QueryRepository<T> — default generic / in-memory implementation
  • IQueryResult<T> with paging support via PagingDescriptor and PageBoundry
  • AddOrUpdate descriptor pattern
  • DataReaderExtensions, DynamicDataRecord, and OData DataServiceQueryExtensions

Quick Start

public class UserService
{
    private readonly IQueryRepository<User> repository;

    public UserService(IQueryRepository<User> repository) =>
        this.repository = repository;

    public async Task<IQueryResult<User>> GetActiveUsersAsync(CancellationToken ct) =>
        await this.repository.ListAsync(new ActiveUsersSpec(), ct);
}

SharedCode.Data.CosmosDb

NuGet

Azure Cosmos DB integration built on top of the official Microsoft.Azure.Cosmos SDK. Targets net8.0 and net9.0.

Highlights

  • Cosmos DB query helpers and logger extensions
  • Query<T> helper for building Cosmos DB LINQ queries

SharedCode.Data.EntityFramework

NuGet

Entity Framework Core integration. Targets net8.0 and net9.0.

Highlights

  • AuditableDbContext — automatically stamps CreatedAt / ModifiedAt on IAuditableEntity
  • EfRepository<T> — EF Core implementation of IQueryRepository<T> and ICommandRepository<T>
  • Entity base class and IAuditableEntity / IAuditedEntity interfaces
  • Specification evaluator wired directly into EF Core queries
  • IDataService / DataService for unit-of-work style operations

Quick Start

// Register with resilient SQL Server connection
services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(
        connectionString,
        sqlOptions => sqlOptions.EnableRetryOnFailure(
            maxRetryCount: 10,
            maxRetryDelay: TimeSpan.FromSeconds(30),
            errorNumbersToAdd: null)));

SharedCode.DependencyInjection

NuGet

Assembly scanning and automatic service registration. Targets netstandard2.0, netstandard2.1, net8.0, and net9.0.

Highlights

  • IDependencyRegister — implement on any class to self-register services
  • DependencyLoader — scans assemblies and invokes all IDependencyRegister implementations
  • CatalogSelector / TypeSourceSelector for fine-grained assembly and type filtering

Quick Start

// In Startup.cs / Program.cs
services.LoadDependencies(typeof(Program).Assembly);

// In any library
public class MyServiceRegistrar : IDependencyRegister
{
    public void Register(IServiceCollection services) =>
        services.AddScoped<IMyService, MyService>();
}

SharedCode.MediatR

NuGet

MediatR pipeline abstractions. Targets net8.0 and net9.0.

Highlights

  • ICommand / ICommand<TResponse> — strongly typed command markers
  • ICommandHandler / ICommandHandler<TCommand, TResponse> — handler contracts
  • IQuery<TResponse> / IQueryHandler<TQuery, TResponse> — query/response contracts
  • Extension method for registering MediatR from an assembly

Quick Start

// Define a command
public sealed record CreateUserCommand(string Name) : ICommand<Guid>;

// Implement a handler
public sealed class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
{
    public async Task<Guid> Handle(CreateUserCommand request, CancellationToken ct)
    {
        // create user ...
        return newUser.Id;
    }
}

// Register in Program.cs
services.AddSharedCodeMediatR(typeof(Program).Assembly);

SharedCode.Web

NuGet

ASP.NET Core helpers. Targets net9.0.

Highlights

  • BaseController — abstract controller base that exposes an IHttpClientFactory
  • Service collection extensions for resilient HTTP clients (Polly retry/wait)
  • Health check registration helpers

Quick Start

[ApiController]
[Route("api/[controller]")]
public class UsersController : BaseController
{
    public UsersController(IHttpClientFactory httpClientFactory)
        : base(httpClientFactory) { }
}

SharedCode.Windows.WPF

NuGet

WPF helpers targeting net9.0-windows10.0.22621.0.

Highlights

  • BindableBase — base class implementing INotifyPropertyChanged
  • Value convertersBooleanToVisibilityConverter, StringToVisibilityConverter, NumberToStringConverter
  • PasswordHelper — attached property for binding PasswordBox.Password
  • Mediator — simple in-process message broker for loosely coupled view-models
  • ModalTemplateAttribute — data-template helper for modal view-models

Note: The WPF community has excellent implementations of commands and more in the CommunityToolkit.Mvvm package. That package is referenced as a dependency and its commands are the recommended approach.


Building from Source

# Clone the repository
git clone https://github.com/improvgroup/sharedcode.git
cd sharedcode

# Restore and build
dotnet build SharedCode.sln

# Run all tests
dotnet test SharedCode.sln

The solution targets .NET 9 for the library projects. The WPF project additionally requires Windows 10 SDK version 10.0.19041.0 or later.


Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository and create a feature branch.
  2. Make your changes, ensuring all existing tests pass (dotnet test SharedCode.sln).
  3. Add or update tests as appropriate.
  4. Open a pull request against the main branch.

Please read the Code of Conduct and Security Policy before contributing.


License

This project is licensed under the MIT License.
Copyright © 2025 improvGroup, LLC and contributors.

About

A library of code shared for free use to help with common scenarios.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors

Languages