Odex.AspNetCore.Generators.OidGen
0.1.1
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
<PackageReference Include="Odex.AspNetCore.Generators.OidGen" Version="0.1.1" />
<PackageVersion Include="Odex.AspNetCore.Generators.OidGen" Version="0.1.1" />
<PackageReference Include="Odex.AspNetCore.Generators.OidGen" />
paket add Odex.AspNetCore.Generators.OidGen --version 0.1.1
#r "nuget: Odex.AspNetCore.Generators.OidGen, 0.1.1"
#:package Odex.AspNetCore.Generators.OidGen@0.1.1
#addin nuget:?package=Odex.AspNetCore.Generators.OidGen&version=0.1.1
#tool nuget:?package=Odex.AspNetCore.Generators.OidGen&version=0.1.1
🔐 Odex.AspNetCore.Generators.OidGen
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
- .NET 9.0 SDK or later
- An ASP.NET Core project
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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - 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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.15)
- Microsoft.Extensions.Options (>= 9.0.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.