AlirezaMahDev.Extensions.ParameterInstance.Abstractions 0.0.1-alpha7

This is a prerelease version of AlirezaMahDev.Extensions.ParameterInstance.Abstractions.
dotnet add package AlirezaMahDev.Extensions.ParameterInstance.Abstractions --version 0.0.1-alpha7
                    
NuGet\Install-Package AlirezaMahDev.Extensions.ParameterInstance.Abstractions -Version 0.0.1-alpha7
                    
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="AlirezaMahDev.Extensions.ParameterInstance.Abstractions" Version="0.0.1-alpha7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlirezaMahDev.Extensions.ParameterInstance.Abstractions" Version="0.0.1-alpha7" />
                    
Directory.Packages.props
<PackageReference Include="AlirezaMahDev.Extensions.ParameterInstance.Abstractions" />
                    
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 AlirezaMahDev.Extensions.ParameterInstance.Abstractions --version 0.0.1-alpha7
                    
#r "nuget: AlirezaMahDev.Extensions.ParameterInstance.Abstractions, 0.0.1-alpha7"
                    
#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 AlirezaMahDev.Extensions.ParameterInstance.Abstractions@0.0.1-alpha7
                    
#: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=AlirezaMahDev.Extensions.ParameterInstance.Abstractions&version=0.0.1-alpha7&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AlirezaMahDev.Extensions.ParameterInstance.Abstractions&version=0.0.1-alpha7&prerelease
                    
Install as a Cake Tool

AlirezaMahDev.Extensions.ParameterInstance.Abstractions

Project Description

This project provides a set of abstractions for implementing parameter-based instance factories in .NET applications. It defines interfaces for creating, caching, and managing object instances based on parameter values, enabling efficient resource utilization and instance reuse patterns.

Key Features

  • Parameter-based instance creation: Create and manage instances based on parameter values
  • Thread-safe instance caching: Built-in support for thread-safe instance caching
  • Flexible lifecycle management: Control how instances are created, cached, and disposed
  • Type-safe generic interfaces: Strongly-typed APIs for better developer experience
  • Dependency injection ready: Designed to work seamlessly with .NET's DI container

Core Components

IParameterInstanceFactory<TParameter>

The base interface for parameter-based instance factories:

  • Options: Gets the configuration options for the factory
  • TryRemove(TParameter): Attempts to remove an instance from the cache

IParameterInstanceFactory<TInstance, TParameter>

Extends the base interface with instance management capabilities:

  • GetOrCreate(TParameter): Gets an existing instance or creates a new one if it doesn't exist
  • Implements IEnumerable<TInstance> for enumerating all created instances

ParameterInstanceFactoryOptions

Configuration options for parameter instance factories:

  • Cache management settings
  • Instance lifetime policies
  • Factory behavior customization

Usage Example

// Define your parameter type
public record UserContext(string UserId, string TenantId);

// Register the factory in DI
services.AddParameterInstanceFactory<UserContext, UserSession>(
    options =>
    {
        // Configure factory options
        options.CacheSize = 1000;
    },
    (provider, context) => new UserSession(context.UserId, context.TenantId));

// Resolve and use the factory
public class UserService
{
    private readonly IParameterInstanceFactory<UserSession, UserContext> _sessionFactory;

    public UserService(IParameterInstanceFactory<UserSession, UserContext> sessionFactory)
    {
        _sessionFactory = sessionFactory;
    }

    public async Task ProcessUserRequest(UserContext context)
    {
        // Get or create a session for the user context
        var session = _sessionFactory.GetOrCreate(context);
        
        // Use the session...
    }
}

Dependencies

  • .NET 10.0: Base framework requirements

Design Principles

  1. Type Safety: Strongly-typed interfaces prevent common errors
  2. Extensibility: Designed to be extended for various caching and lifecycle scenarios
  3. Performance: Efficient instance management with minimal overhead
  4. Thread Safety: Built-in support for concurrent access
  5. Dependency Injection: First-class support for .NET's DI container

When to Use

This library is particularly useful when you need to:

  • Cache expensive-to-create objects based on parameters
  • Manage the lifecycle of parameter-dependent instances
  • Implement the flyweight pattern
  • Create thread-safe instance caches
  • Implement multi-tenant services where each tenant gets its own instance

Implementation Notes

  • The factory pattern implemented here is particularly useful for scenarios where object creation is expensive
  • The cache is automatically managed by the factory based on the provided options
  • Implementations should ensure thread safety when creating and accessing instances
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AlirezaMahDev.Extensions.ParameterInstance.Abstractions:

Package Downloads
AlirezaMahDev.Extensions.ParameterInstance

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1-alpha7 408 12/8/2025
0.0.1-alpha 272 12/7/2025