Octacer.Generics 1.1.0

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

Octacer.Generics

Comprehensive utility library with helpers for data services, networking, encryption, file handling, email services, S3 integration, and more. Includes generic database operations, HTTP client utilities, and service registration attributes for dependency injection.

Features

🗄️ Database Services

  • Generic SQL Query Builder with type-safe operations
  • Dynamic WHERE clause generation with parameterized queries
  • Bulk operations and transaction support
  • Database service abstractions for multiple providers
  • SQL parameter collection utilities

🌐 Networking & HTTP

  • Generic HTTP Client with configurable base implementation
  • Network utilities for connection testing and validation
  • REST API helpers with automatic serialization
  • Retry mechanisms with exponential backoff
  • Custom exception handling for network operations

🔐 Security & Encryption

  • Symmetric encryption utilities (OctaSymmetric)
  • Hash generation and validation helpers
  • Secure string handling and validation
  • Email address validation with comprehensive rules
  • URL validation and manipulation

📁 File Storage Services

  • Local File System storage with directory management
  • Azure Blob Storage integration with container management
  • Amazon S3 support with bucket operations
  • Google Drive API integration with folder management
  • Unified interface for all storage providers
  • MIME type detection and file extension helpers

📧 Email Services

  • SMTP email sending with HTML and text support
  • Gmail API integration for advanced email operations
  • Email template support with dynamic content
  • Attachment handling for multiple file types
  • Email validation and formatting utilities

🔧 Service Registration

  • Automatic service discovery with attributes
  • Dependency injection helpers for different lifetimes
  • Scoped, Singleton, and Transient service registration
  • Service factory patterns for complex object creation

🛠️ Helper Utilities

  • String manipulation extensions and validators
  • Collection helpers for LINQ operations and transformations
  • DateTime utilities with timezone support
  • JSON serialization helpers with custom converters
  • Reflection utilities for dynamic type operations
  • Enum helpers with attribute support

Installation

dotnet add package Octacer.Generics

Quick Start

Database Services

using Octacer.Generics.Services.DataService;

// Generic database operations
var dbService = new DatabaseService(connectionString);

// Execute parameterized queries
var users = await dbService.ExecuteQueryAsync<User>(
    "SELECT * FROM Users WHERE IsActive = @active",
    new { active = true }
);

// Build dynamic WHERE clauses
var whereClause = WhereGenerator.Build()
    .Add("Name", "John", SqlOperator.Like)
    .Add("Age", 25, SqlOperator.GreaterThanOrEqual)
    .ToString(); // "Name LIKE @Name AND Age >= @Age"

File Storage

using Octacer.Generics.Services.Storage;

// Local file storage
var localStore = new LocalFileStoreService("/uploads");
await localStore.SaveFileAsync("documents", "file.pdf", fileStream);

// Azure Blob Storage
var azureStore = new AzureBlobFileService(connectionString, "container");
await azureStore.UploadFileAsync("folder", "file.pdf", fileStream);

// Amazon S3
var s3Store = new S3FileService(accessKey, secretKey, region, "bucket");
await s3Store.UploadFileAsync("folder/file.pdf", fileStream);

// Google Drive
var driveStore = new GoogleDriveFileStoreService();
GoogleDriveFileStoreService.Init("credentials.json", "root-folder-id");
await driveStore.UploadFileFromUrlAsync("docs", "file.pdf", "https://example.com/file.pdf");

HTTP Client

using Octacer.Generics.Services.Network;

var httpClient = new OctaNetwork_GenericHttpClient("https://api.example.com");

// GET request with automatic deserialization
var result = await httpClient.GetAsync<ApiResponse>("/users");

// POST request with retry
var response = await httpClient.PostAsync("/users", newUser, retryCount: 3);

// Custom headers and authentication
httpClient.SetBearerToken("your-jwt-token");
httpClient.SetHeader("Custom-Header", "value");

Service Registration

using Octacer.Generics.ServiceRegistrars;

// Automatic service registration
public class DatabaseService : IDbService
{
    // Service implementation
}

// Register with attributes
[TransientService(typeof(IDbService))]
public class TransientDbService : IDbService { }

[ScopedService(typeof(IUserService))]
public class UserService : IUserService { }

[SingletonService(typeof(IConfigService))]
public class ConfigService : IConfigService { }

// In Program.cs
builder.Services.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());

Encryption & Security

using Octacer.Generics.Helpers;

// Symmetric encryption
var encrypted = OctaSymmetric.Encrypt("sensitive data", "encryption-key");
var decrypted = OctaSymmetric.Decrypt(encrypted, "encryption-key");

// Validation helpers
bool isValid = EmailHelper.IsValidEmail("user@example.com");
bool isSecure = UrlHelper.IsSecureUrl("https://example.com");

// String utilities
string cleaned = StringHelper.RemoveSpecialCharacters("Hello, World!");
string slug = StringHelper.ToSlug("My Blog Post Title"); // "my-blog-post-title"

Helper Extensions

using Octacer.Generics.Helpers;

// String extensions
"user@example.com".IsValidEmailAddress(); // true
"Hello World".ToSlug(); // "hello-world"
"JSON_STRING".IsValidJson(); // true/false

// Collection extensions
var list = new List<int> { 1, 2, 3, 4, 5 };
var chunks = list.ChunkBy(2); // [[1,2], [3,4], [5]]

// DateTime helpers
DateTime.Now.ToUnixTimestamp(); // Unix timestamp
DateTimeHelper.ParseFlexible("2024-01-01"); // Flexible date parsing

// Number helpers
NumberHelpers.FormatFileSize(1024); // "1 KB"
NumberHelpers.GenerateRandomNumber(1, 100); // Random number in range

Configuration

Google Services Setup

{
  "Google": {
    "CredentialsPath": "/path/to/service-account.json",
    "RootFolderId": "google-drive-root-folder-id"
  }
}

AWS S3 Configuration

{
  "AWS": {
    "AccessKey": "your-access-key",
    "SecretKey": "your-secret-key",
    "Region": "us-east-1",
    "BucketName": "your-bucket"
  }
}

Azure Blob Storage

{
  "Azure": {
    "StorageConnectionString": "your-connection-string",
    "ContainerName": "your-container"
  }
}

Advanced Usage

Custom Database Provider

public class CustomDbService : DatabaseService
{
    public CustomDbService(string connectionString) : base(connectionString) { }
    
    public async Task<List<T>> GetPagedResultsAsync<T>(int page, int size)
    {
        var query = GenericQueries.BuildSelectQuery<T>()
            .AddPaging(page, size);
            
        return await ExecuteQueryAsync<T>(query.ToString(), query.Parameters);
    }
}

Custom File Storage Provider

public class CustomFileStore : IFileStoreService
{
    public async Task<string> SaveFileAsync(string path, string filename, Stream fileStream)
    {
        // Custom implementation
        return savedFilePath;
    }
    
    // Implement other interface members
}

Service Factory Pattern

[SingletonService(typeof(IFileStoreFactory))]
public class FileStoreFactory : IFileStoreFactory
{
    public IFileStoreService CreateFileStore(StorageType type)
    {
        return type switch
        {
            StorageType.Local => new LocalFileStoreService(),
            StorageType.Azure => new AzureBlobFileService(),
            StorageType.S3 => new S3FileService(),
            StorageType.GoogleDrive => new GoogleDriveFileStoreService(),
            _ => throw new NotSupportedException()
        };
    }
}

Testing Utilities

// Unit testing helpers
var mockData = TestHelper.GenerateRandomUsers(100);
var testEmail = TestHelper.GenerateValidEmail();
var testUrl = TestHelper.GenerateValidUrl();

// Performance testing
using var timer = PerformanceHelper.StartTimer();
// ... your code ...
var elapsed = timer.Stop(); // Returns TimeSpan

Dependencies

  • .NET 9.0+
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Microsoft.Extensions.Logging.Abstractions
  • AWSSDK.S3 (for S3 operations)
  • Google.Apis.Drive.v3 (for Google Drive)
  • Microsoft.Data.SqlClient (for SQL Server)
  • RestSharp (for HTTP operations)
  • HtmlAgilityPack (for HTML processing)

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Support

For support and questions, please open an issue on the GitHub repository.

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 (1)

Showing the top 1 NuGet packages that depend on Octacer.Generics:

Package Downloads
Octacer.Web

Complete ASP.NET Core admin panel framework with JWT-based Identity API, enum-based role discovery, and comprehensive authentication/authorization features. Includes Swagger documentation, role management, and customizable UI components.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 353 6/11/2025
1.0.4 238 4/21/2025
1.0.0 226 4/14/2025

v1.1.0: Enhanced utilities with improved data services, networking helpers, and service registration attributes. Added email services, S3 file handling, and comprehensive generic database operations.