NCode.Collections.Providers 1.0.0

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

ci Nuget

NCode.Collections.Providers

A .NET library for building dynamic, change-aware collection providers that aggregate multiple data sources with automatic change notifications.

Features

Core Abstractions (NCode.Collections.Providers.Abstractions)

  • ICollectionDataSource<T> - Interface for data sources that provide a collection of items with change token support
  • ICollectionProvider<TItem, TCollection> - Interface for providers that aggregate multiple data sources into a unified collection
  • ISupportChangeToken - Interface for objects that support change notification via IChangeToken
  • INullChangeToken - Marker interface for change tokens that never signal changes

Data Source Implementations (NCode.Collections.Providers)

  • Static Data Source - Wraps an immutable collection that never changes
  • Observable Data Source - Wraps an ObservableCollection<T> with automatic change notifications when items are added, removed, or modified
  • Composite Data Source - Aggregates multiple data sources into a single unified collection with consolidated change notifications
  • Periodic Polling Data Source - Periodically fetches data from external sources (APIs, databases, files) with configurable refresh intervals and error handling

Factory Interfaces

  • ICollectionDataSourceFactory - Creates data source instances for different scenarios
  • ICollectionProviderFactory - Creates collection provider instances that aggregate data sources

Change Token Support

  • Automatic propagation of change notifications from data sources to consumers
  • Lazy initialization of change tokens for efficiency
  • Thread-safe collection updates when changes are detected
  • Support for additional change token producers beyond data sources (e.g., configuration changes)

Dependency Injection Integration

  • AddCollectionProviders() extension method for IServiceCollection
  • Singleton registration of factories for optimal performance
  • Support for DI-managed data source lifetimes

Installation

dotnet add package NCode.Collections.Providers

Or for abstractions only:

dotnet add package NCode.Collections.Providers.Abstractions

Quick Start

Register Services

services.AddCollectionProviders();

Create a Static Data Source

var factory = serviceProvider.GetRequiredService<ICollectionDataSourceFactory>();
var dataSource = factory.CreateStatic(new[] { "item1", "item2", "item3" });

Create an Observable Data Source

var observableCollection = new ObservableCollection<string>();
var dataSource = factory.CreateObservable(observableCollection);

// Changes to observableCollection will trigger change notifications
observableCollection.Add("new item");

Create a Periodic Polling Data Source

var dataSource = factory.CreatePeriodicPolling(
    state: httpClient,
    initialCollection: Array.Empty<User>(),
    refreshInterval: TimeSpan.FromMinutes(5),
    refreshCollectionAsync: async (client, current, ct) =>
    {
        var users = await client.GetFromJsonAsync<List<User>>("/api/users", ct);
        return RefreshCollectionResultFactory.Changed(users);
    },
    handleExceptionAsync: async (ex, ct) =>
    {
        logger.LogError(ex.SourceException, "Failed to refresh users");
    }
);

Create a Collection Provider

var providerFactory = serviceProvider.GetRequiredService<ICollectionProviderFactory>();
var provider = providerFactory.Create(
    collectionFactory: items => items.ToList(),
    dataSources: serviceProvider.GetServices<ICollectionDataSource<User>>()
);

// Access the aggregated collection
var users = provider.Collection;

// Subscribe to changes
ChangeToken.OnChange(provider.GetChangeToken, () =>
{
    Console.WriteLine("Collection changed!");
    var updatedUsers = provider.Collection;
});

License

Licensed under the Apache License, Version 2.0. See LICENSE.txt for details.

Target Frameworks

  • .NET 8.0
  • .NET 10.0

Release Notes

  • v1.0.0 - Initial release
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 was computed.  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 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. 
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.0.0 85 1/19/2026

Built on 2026-01-19 18:03:26Z