eBuildingBlocks.Common 2.0.0

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

eBuildingBlocks.Common

A lightweight utility library for .NET applications that provides common utilities, extensions, and helper classes for cross-cutting concerns.

Overview

eBuildingBlocks.Common is a foundational utility library that provides essential common utilities, helper classes, and extensions that can be used across different layers of your application. It contains lightweight, dependency-free utilities that enhance development productivity.

Key Features

🔧 Utility Classes

  • Guid Generator: Modern GUID generation utilities
  • Custom Claim Types: Standardized JWT claim type definitions
  • Extension Methods: Common extension methods for everyday tasks

🆔 Identity & Security

  • Custom Claim Types: Predefined claim types for JWT tokens
  • Tenant Support: Multi-tenancy claim definitions
  • Security Utilities: Common security-related utilities

🛠️ Development Utilities

  • Guid Generation: Modern GUID v7 generation
  • Common Extensions: Reusable extension methods
  • Helper Classes: Utility classes for common operations

Installation

dotnet add package eBuildingBlocks.Common

Quick Start

1. Using Guid Generator

using eBuildingBlocks.Common.utils;

// Generate a new GUID v7
var newGuid = GuidGenerator.NewV7();

2. Using Custom Claim Types

using eBuildingBlocks.Common.utils;

// Access predefined claim types
var tenantIdClaim = CustomClaimTypes.TenantId; // "tenant_id"

Features in Detail

Guid Generator

The library provides a modern GUID generation utility:

using eBuildingBlocks.Common.utils;

public class UserService
{
    public User CreateUser(string name)
    {
        var user = new User
        {
            Id = GuidGenerator.NewV7(), // Modern GUID v7
            Name = name,
            CreatedAt = DateTime.UtcNow
        };
        
        return user;
    }
}

Benefits of GUID v7:

  • Time-ordered for better database performance
  • Monotonic within the same millisecond
  • Compatible with distributed systems
  • Better for indexing and sorting

Custom Claim Types

Standardized JWT claim type definitions:

using eBuildingBlocks.Common.utils;

public class JwtService
{
    public string GenerateToken(User user)
    {
        var claims = new List<Claim>
        {
            new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
            new Claim(ClaimTypes.Name, user.Username),
            new Claim(CustomClaimTypes.TenantId, user.TenantId.ToString())
        };
        
        // Token generation logic...
        return token;
    }
}
Available Claim Types
public static class CustomClaimTypes
{
    public const string TenantId = "tenant_id";
    // Additional claim types can be added here
}

Project Structure

eBuildingBlocks.Common/
├── utils/
│   ├── CustomClaimTypes.cs
│   └── GuidGenerator.cs
└── eBuildingBlocks.Common.csproj

Usage Examples

Entity Creation with Modern GUIDs

using eBuildingBlocks.Common.utils;

public abstract class BaseEntity
{
    public Guid Id { get; set; }
    
    protected BaseEntity()
    {
        if (Id == Guid.Empty)
        {
            Id = GuidGenerator.NewV7();
        }
    }
}

JWT Token Generation

using eBuildingBlocks.Common.utils;
using System.Security.Claims;

public class TokenService
{
    public string CreateToken(User user)
    {
        var claims = new[]
        {
            new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
            new Claim(ClaimTypes.Name, user.Username),
            new Claim(CustomClaimTypes.TenantId, user.TenantId.ToString())
        };
        
        // Token generation logic...
        return token;
    }
}

Multi-Tenant Application

using eBuildingBlocks.Common.utils;

public class TenantAwareService
{
    public async Task<IActionResult> GetUserData(HttpContext context)
    {
        var tenantIdClaim = context.User.FindFirst(CustomClaimTypes.TenantId);
        
        if (tenantIdClaim == null)
        {
            return Unauthorized("Tenant information not found");
        }
        
        var tenantId = Guid.Parse(tenantIdClaim.Value);
        var userData = await _userService.GetByTenantAsync(tenantId);
        
        return Ok(userData);
    }
}

Database Entity with Modern GUIDs

using eBuildingBlocks.Common.utils;

public class Product : BaseEntity
{
    public string Name { get; set; }
    public decimal Price { get; set; }
    public Guid TenantId { get; set; }
    
    public Product()
    {
        // Id is automatically set to GUID v7 in BaseEntity constructor
    }
}

Dependencies

  • .NET 9.0 - Target framework
  • No external dependencies - Lightweight utility library

Performance Considerations

GUID Generation

  • GUID v7: Time-ordered, better for database indexing
  • Performance: Optimized for high-frequency generation
  • Uniqueness: Guaranteed uniqueness across distributed systems

Memory Usage

  • Lightweight: Minimal memory footprint
  • No allocations: Efficient utility methods
  • Thread-safe: Safe for concurrent usage

Best Practices

Using GUID Generator

// ✅ Good - Use for new entities
var newEntity = new MyEntity
{
    Id = GuidGenerator.NewV7()
};

// ❌ Avoid - Don't use for existing entities
var existingEntity = new MyEntity
{
    Id = GuidGenerator.NewV7() // This will overwrite existing ID
};

Using Custom Claim Types

// ✅ Good - Use predefined claim types
new Claim(CustomClaimTypes.TenantId, tenantId.ToString())

// ❌ Avoid - Don't hardcode claim types
new Claim("tenant_id", tenantId.ToString())

Extension Points

Adding Custom Claim Types

public static class CustomClaimTypes
{
    public const string TenantId = "tenant_id";
    public const string UserRole = "user_role";
    public const string Department = "department";
    // Add more as needed
}

Extending Guid Generator

public static class GuidGeneratorExtensions
{
    public static Guid NewSequentialGuid()
    {
        // Custom sequential GUID generation
        return GuidGenerator.NewV7();
    }
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

Copyright © Inam Ul Haq. All rights reserved.

Support

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.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on eBuildingBlocks.Common:

Package Downloads
eBuildingBlocks.Domain

Reusable building block for the ecosystem. Implements core cross-cutting concerns, infrastructure, or domain utilities for .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 222 8/5/2025
1.0.6 221 8/5/2025
1.0.5 228 7/20/2025
1.0.4 61 7/19/2025
1.0.1 61 7/19/2025