Odex.AspNetCore.Generators.OidGen 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Odex.AspNetCore.Generators.OidGen --version 0.1.1
                    
NuGet\Install-Package Odex.AspNetCore.Generators.OidGen -Version 0.1.1
                    
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="Odex.AspNetCore.Generators.OidGen" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Odex.AspNetCore.Generators.OidGen" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Odex.AspNetCore.Generators.OidGen" />
                    
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 Odex.AspNetCore.Generators.OidGen --version 0.1.1
                    
#r "nuget: Odex.AspNetCore.Generators.OidGen, 0.1.1"
                    
#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 Odex.AspNetCore.Generators.OidGen@0.1.1
                    
#: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=Odex.AspNetCore.Generators.OidGen&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Odex.AspNetCore.Generators.OidGen&version=0.1.1
                    
Install as a Cake Tool

🔐 Odex.AspNetCore.Generators.OidGen

NuGet Version NuGet Downloads License: MIT

Unique ID Generator for ASP.NET Core
Simple, flexible, and customizable unique ID generation library


📦 Overview

Odex.AspNetCore.Generators.OidGen (O'shabi Unique ID Generator) is a lightweight, dependency-injection-friendly library for generating unique identifiers in ASP.NET Core applications. It provides a clean interface for creating IDs with digits, characters, mixed characters, prefixes, suffixes, and mask-based formats — all with optional special character support.

Key Features:

  • Numeric IDs – Generate random digit-only strings.
  • Character IDs – Generate alphabetic IDs with uppercase/lowercase control.
  • Mixed IDs – Combine digits, letters, and optional special characters.
  • Prefix/Suffix – Conveniently attach prefixes or suffixes to generated IDs.
  • Mask Formatting – Define custom patterns using placeholders.
  • Configurable Special Characters – Customize the set of allowed special characters via OidOptions.
  • DI-Ready – Register with a single extension method in your Program.cs.

🚀 Getting Started

Prerequisites

Installation

The library is published as a NuGet package:

dotnet add package Odex.AspNetCore.Generators.OidGen

Or use the Package Manager Console:

Install-Package Odex.AspNetCore.Generators.OidGen

Basic Setup

1. Register OidGen in Program.cs

using Odex.AspNetCore.Generators.OidGen;

var builder = WebApplication.CreateBuilder(args);

// Add with default options
builder.Services.AddOidGen();

// Or configure custom options
builder.Services.AddOidGen(options =>
{
    options.Placeholder = '*';
    options.SpecialChars = "!@#$%";
});

var app = builder.Build();

2. Inject and Use IOidGen in a Controller or Service

using Microsoft.AspNetCore.Mvc;
using Odex.AspNetCore.Generators.OidGen.Interfaces;

[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
    private readonly IOidGen _oidGen;

    public OrdersController(IOidGen oidGen)
    {
        _oidGen = oidGen;
    }

    [HttpPost]
    public IActionResult CreateOrder()
    {
        // Generate a unique order ID
        var orderId = _oidGen.WithPrefix(12, "ORD-", useSpecialCharacters: false);
        // Result example: ORD-x7K9mP2qR5nL
        
        return Ok(new { OrderId = orderId });
    }
}

✨ Features

Feature Description
🔢 Digit Generation Generates random numeric strings of specified length.
🔤 Character Generation Generates alphabetic strings with optional uppercase-only or lowercase-only constraints.
🔀 Mixed Generation Combines digits, uppercase, lowercase, and optional special characters.
🏷️ Prefix Support Attach a prefix string to the beginning of a generated mixed ID.
🏁 Suffix Support Attach a suffix string to the end of a generated mixed ID.
🎭 Mask Formatting Define custom ID patterns using a placeholder character (default #).
⚙️ Configurable Special Chars Override the default special character set (-_) via OidOptions.
💉 Dependency Injection Clean registration via AddOidGen() extension method on IServiceCollection.

🚀 Usage Examples

Generate a 10-Digit Numeric ID

var numericId = _oidGen.Digit(10);
// Result: "8472910536"

Generate an 8-Character Uppercase-Only ID

var upperId = _oidGen.Character(8, uppercaseOnly: true);
// Result: "KXMVRQPT"

Generate a 12-Character Mixed ID with Special Characters

var mixedId = _oidGen.Mixed(12, useSpecialCharacters: true);
// Result: "aB3-xK9_mP2q"

Generate an ID with a Prefix

var prefixedId = _oidGen.WithPrefix(8, "USR-", useSpecialCharacters: false);
// Result: "USR-a3Fk9M2x"

Generate an ID with a Suffix

var suffixedId = _oidGen.WithSuffix(6, "-2024", useSpecialCharacters: false);
// Result: "xK9mP2-2024"

Generate an ID Using a Mask

var maskedId = _oidGen.Formatted("PROD-###-####", placeholder: '#');
// Result: "PROD-a3F-k9M2"

Custom Mask with Different Placeholder

// Using default options (Placeholder = '#')
var phoneId = _oidGen.Formatted("+1 (###) ###-####");
// Result: "+1 (473) 829-1056"

// Or with custom placeholder if configured
var customId = _oidGen.Formatted("TXN-***-***", placeholder: '*');
// Result: "TXN-a3F-k9M"

Complete Service Example

public class UserService
{
    private readonly IOidGen _oidGen;

    public UserService(IOidGen oidGen)
    {
        _oidGen = oidGen;
    }

    public string GenerateUserId()
    {
        return _oidGen.WithPrefix(10, "USER-");
        // Result: "USER-a3Fk9M2xR5"
    }

    public string GenerateApiKey()
    {
        return _oidGen.Formatted("key_####################", useSpecialCharacters: false);
        // Result: "key_a3Fk9M2xR5nLpT8sWqY"
    }

    public string GenerateOrder[Odex.AspNetCore.Generators.OidGen.csproj](Odex.AspNetCore.Generators.OidGen.csproj)Number()
    {
        return _oidGen.Formatted("ORD-####-####", useSpecialCharacters: false);
        // Result: "ORD-a3Fk-9M2x"
    }
}

📂 Namespace Map

Namespace Purpose
Odex.AspNetCore.Generators.OidGen.Interfaces IOidGen interface
Odex.AspNetCore.Generators.OidGen.Options OidOptions configuration class
Odex.AspNetCore.Generators.OidGen.Services OidGen implementation
Odex.AspNetCore.Generators.OidGen ServiceCollectionExtension for DI registration

🤝 Contributing

Contributions are welcome! Please follow the standard GitHub flow:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License – see the LICENSE file for details.


Built with ❤️ - A clean and simple ID generation for ASP.NET Core

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
0.2.0 100 5/17/2026
0.1.2 102 4/30/2026
0.1.1 95 4/30/2026
0.1.0 94 4/30/2026