Aspireng.Infrastructure 1.1.3

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

Aspireng.Infrastructure

Purpose: Pluggable repository implementations and cross-cutting adapters that back the domain abstractions.

Includes:

  • Repositories: In-Memory, File, EF Core
  • Encryption: IEntityProtector + NoOpEntityProtector
  • Caching adapter: MemoryCacheAppCache (implements IAppCache)
  • DI Extensions: one-liners to register preferred storage per microservice

Repositories

InMemoryRepository<T>

  • Thread-safe ConcurrentDictionary.
  • Great for tests/dev or ephemeral data.
  • Evaluates specifications in memory.

FileRepository<T>

  • One JSON file per entity (*.stone).
  • Per-file SemaphoreSlim for process-local concurrency.
  • Evaluates specifications in memory.
  • Options
  services.AddFileRepositories(o => o.RootDirectory = "App_Data");

⚠️ If multiple processes write to the same directory, consider a distributed lock or avoid sharing directories.

EfRepository<T>

  • Translates specifications to SQL via EF Core.
  • Requires a registered DbContext in DI.
  • Uses AsNoTracking() for reads; call Update/AddAsync for writes.

Encryption

Implement IEntityProtector to bridge your existing EncryptAllField/DecryptAllField logic:

public sealed class MyEntityProtector : IEntityProtector
{
    public void Encrypt<T>(T entity) { /* call your encryption helpers */ }
    public void Decrypt<T>(T entity) { /* call your decryption helpers */ }
}

Register it instead of NoOpEntityProtector.


Caching Adapter

MemoryCacheAppCache wraps IMemoryCache and implements IAppCache.

services.AddBuildingBlocksCaching(); // adds IMemoryCache + IAppCache

If you already use IIsolatedCache, create an adapter that implements IAppCache.


DI Registration

Use the extensions in Extensions/RepositoryRegistration.cs.

using Microsoft.EntityFrameworkCore;
using Aspireng.Infrastructure.Extensions;
using Aspireng.Infrastructure.Persistence.File;
// using Aspireng.Infrastructure.Persistence.EfCore;

// Add cache adapter
services.AddBuildingBlocksCaching();

// Choose ONE global default:
services.AddFileRepositories(o => o.RootDirectory = builder.Configuration["Persistence:RootDirectory"] ?? "App_Data");

// or EF Core:
// services.AddDbContext<AppDbContext>(opt => opt.UseSqlServer(cfg.GetConnectionString("Default")));
// services.AddEfRepositories();

// or In-Memory:
// services.AddInMemoryRepositories();

// Per-aggregate overrides are allowed:
services.AddScoped<IRepository<MyEntity>, EfRepository<MyEntity>>();

Using From a Microservice

// Program.cs
builder.Services.AddBuildingBlocksCaching();
builder.Services.AddFileRepositories(o => o.RootDirectory = "App_Data");

// Application service
builder.Services.AddScoped<OrderService>(); // your service inheriting ReadWriteService<Order>

Concurrency & Consistency

  • Optimistic concurrency: add a RowVersion (byte[]) to your service’s entities and configure EF with [Timestamp].
  • File repository: per-file locks are per-process only. For cross-process access, prefer EF Core or introduce a distributed lock.

Pack

./build/release-aspireng.cmd

The package id should be Aspireng.Infrastructure.

Product Compatible and additional computed target framework versions.
.NET 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.1.3 63 8/22/2025
1.1.2 62 8/22/2025
1.1.1 63 8/22/2025
1.0.9 60 8/22/2025
1.0.7 75 8/22/2025
1.0.6 124 8/21/2025
1.0.5 124 8/20/2025
1.0.4 125 8/20/2025
1.0.2 122 8/20/2025
1.0.1 121 8/20/2025
1.0.0 121 8/20/2025