Oakrey.Applications.Json.Abstractions
3.0.4
See the version list below for details.
dotnet add package Oakrey.Applications.Json.Abstractions --version 3.0.4
NuGet\Install-Package Oakrey.Applications.Json.Abstractions -Version 3.0.4
<PackageReference Include="Oakrey.Applications.Json.Abstractions" Version="3.0.4" />
<PackageVersion Include="Oakrey.Applications.Json.Abstractions" Version="3.0.4" />
<PackageReference Include="Oakrey.Applications.Json.Abstractions" />
paket add Oakrey.Applications.Json.Abstractions --version 3.0.4
#r "nuget: Oakrey.Applications.Json.Abstractions, 3.0.4"
#:package Oakrey.Applications.Json.Abstractions@3.0.4
#addin nuget:?package=Oakrey.Applications.Json.Abstractions&version=3.0.4
#tool nuget:?package=Oakrey.Applications.Json.Abstractions&version=3.0.4
Oakrey.Applications.Json.Abstractions
A .NET 10 library that defines the IJsonService abstraction for JSON serialization and
deserialization operations. It contains no implementation code, no logging, and no telemetry
dependencies, making it the correct reference for libraries and application layers that need
JSON access without coupling to a concrete implementation.
Main features
| Method | Description |
|---|---|
LoadJson<T>(fileName) |
Deserializes a JSON file to T (synchronous) |
LoadJsonAsync<T>(fileName, ct) |
Deserializes a JSON file to T (asynchronous, CancellationToken aware) |
LoadObjectsFromJsonFilesAsync<T>(folder, extension, ct) |
Loads and deserializes all JSON files in a directory matching the given extension into a List<T> |
SaveJson<T>(value, fileName) |
Serializes value to a JSON file (synchronous) |
SaveJsonAsync<T>(value, fileName) |
Serializes value to a JSON file (fire-and-forget async) |
SaveJsonFiles<TNamed>(jsons, folder, extension) |
Serializes a collection of IName items to individual files named after each item in the given directory |
SaveJsonFiles requires TNamed to implement IName from Oakrey.Collections, which
provides a Name property used as the file name.
Architecture
classDiagram
class IJsonService {
+LoadJson~T~(fileName) T
+LoadJsonAsync~T~(fileName, ct) Task~T~
+LoadObjectsFromJsonFilesAsync~T~(folder, extension, ct) Task~List~T~~
+SaveJson~T~(value, fileName)
+SaveJsonAsync~T~(value, fileName)
+SaveJsonFiles~TNamed~(jsons, folder, extension)
}
class JsonService {
<<Oakrey.Applications.Json>>
}
class IFileService {
<<Oakrey.Applications.Files.Abstractions>>
}
IJsonService <|.. JsonService
JsonService --> IFileService
The concrete implementation lives in the separate Oakrey.Applications.Json package.
Consuming projects should reference only this abstractions package and register the
implementation via the extension provided by Oakrey.Applications.Json.
Requirements
- .NET 10 or later
Oakrey.Collections� provides theINameinterface required bySaveJsonFiles
Installation
dotnet add package Oakrey.Applications.Json.Abstractions
To also include the concrete implementation:
dotnet add package Oakrey.Applications.Json
Example usage
Registering the service
// In your composition root, reference Oakrey.Applications.Json for the extension method.
services.AddJsonService();
Deserializing a single file
public sealed class ConfigLoader
{
private readonly IJsonService _jsonService;
public ConfigLoader(IJsonService jsonService)
{
_jsonService = jsonService;
}
public async Task<AppConfig> LoadAsync(string path, CancellationToken cancellationToken)
{
return await _jsonService.LoadJsonAsync<AppConfig>(path, cancellationToken);
}
}
Loading all files from a directory
List<Profile> profiles = await _jsonService.LoadObjectsFromJsonFilesAsync<Profile>(
folder: @"C:\Data\Profiles",
extension: "json",
cancellationToken: cancellationToken);
Saving a batch of named objects
// Profile implements IName, so each item is saved as "{profile.Name}.json".
_jsonService.SaveJsonFiles(profiles, folder: @"C:\Data\Profiles", extension: "json");
Development notes
- This package contains only the
IJsonServiceinterface. No serializer, logger, or tracer code is included. - The concrete implementation (
JsonService) is inOakrey.Applications.Json. It usesSystem.Text.Jsonwith stream-based I/O viaIFileService, structured logging viaOakrey.Log, and OpenTelemetry activity spans viaOakrey.Telemetry. - Both packages share the
Oakrey.Applications.Jsonroot namespace. - The
Oakrey.Collectionsdependency is required here becauseINameappears in theSaveJsonFilescontract on the interface itself.
License
MIT � Copyright � Oakrey 2016-present
| 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
- Oakrey.Collections (>= 2.0.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Oakrey.Applications.Json.Abstractions:
| Package | Downloads |
|---|---|
|
Oakrey.Applications.Json
Provides IJsonService for stream-based JSON serialization and deserialization using System.Text.Json, with async CancellationToken support, batch directory load, IName-keyed batch save, and built-in logging and OpenTelemetry tracing via IFileService. |
|
|
Oakrey.Applications.ControlObjects
A .NET WPF library for building interactive, validated control objects. Provides a base class hierarchy for reactive sending objects, enable/disable and timer-driven variants, cancelable async operations, device abstraction, multi-key gesture support, and observable collections with automatic JSON persistence. |
|
|
Oakrey.Applications.Ohm.CAN
Service layer library for managing CAN bus hardware devices and channels. Provides device discovery, connection lifecycle management, reactive IObservable streams for received frames and status changes, per-channel transmit, USB hot-plug detection, and persistent JSON configuration. |
GitHub repositories
This package is not used by any popular GitHub repositories.