This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

Skip to main content Skip to navigation

DataFileServiceExtensions Pennington.Data

DI helpers for registering YAML/JSON data files that hot-reload when the underlying file changes on disk.

Methods

AddDataDirectory<TItem>

#
public static IServiceCollection AddDataDirectory<TItem>(IServiceCollection services, string name, string path)

Registers every .yml, .yaml, and .json file in path as a single aggregated IReadOnlyList accessible through IDataFiles under the lookup key name. Each file contributes one record, or several when its root is an array; files are ordered by name. Edits, additions, and removals in the directory invalidate the cached value so the next read returns the fresh content.

Parameters

services IServiceCollection
The service collection.
name string
Logical lookup key. Case-insensitive; must be unique across all registered data files.
path string
Path to the directory. Resolved against the current working directory if relative.

Returns

IServiceCollection

AddDataFile<T>

#
public static IServiceCollection AddDataFile<T>(IServiceCollection services, string name, string path)

Registers path as a data file accessible through IDataFiles under the lookup key name. Format is inferred from the file extension (.yml, .yaml, .json). Edits to the file invalidate the cached value so the next read returns the fresh content.

Parameters

services IServiceCollection
The service collection.
name string
Logical lookup key. Case-insensitive; must be unique across all registered data files.
path string
Path to the data file. Resolved against the current working directory if relative.

Returns

IServiceCollection

Pennington.Data.DataFileServiceExtensions

namespace Pennington.Data;

/// DI helpers for registering YAML/JSON data files that hot-reload when the underlying file changes on disk.
public class DataFileServiceExtensions
{
    /// Registers every .yml, .yaml, and .json file in path as a single aggregated IReadOnlyList accessible through IDataFiles under the lookup key name. Each file contributes one record, or several when its root is an array; files are ordered by name. Edits, additions, and removals in the directory invalidate the cached value so the next read returns the fresh content.
    
public static IServiceCollection AddDataDirectory<TItem>(IServiceCollection services, string name, string path)
; /// Registers path as a data file accessible through IDataFiles under the lookup key name. Format is inferred from the file extension (.yml, .yaml, .json). Edits to the file invalidate the cached value so the next read returns the fresh content.
public static IServiceCollection AddDataFile<T>(IServiceCollection services, string name, string path)
; }