TurgayAcar.WebLibrary 1.4.0

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

WebLibrary - .NET 9 Web Development Library

A comprehensive .NET 9 Class Library that provides generic methods, utilities, and operations for web development.

Features

๐Ÿ”ง Core Components

  • Global Configuration: Centralized configuration management
  • ServiceResult Model: Generic result wrapper for service operations
  • HTTP Client Helper: Generic HTTP client operations
  • Validation Helper: Data validation utilities
  • Generic Extensions: Extension methods for common operations
  • Generic Utilities: General-purpose utility methods
  • Generic Service Base: Abstract base class for CRUD operations

๐Ÿ” Security & Authentication

  • JWT Token Management: Token generation, validation, and claim extraction
  • Password Security: BCrypt hashing, verification, and strength checking
  • Encryption Utilities: AES encryption, SHA hashing, HMAC, and secure random generation

๐Ÿ“Š Data Processing

  • CSV Operations: Import/export with CsvHelper
  • Excel Operations: Read/write Excel files with EPPlus
  • Data Transformation: JSON/Dictionary conversion, object copying, and comparison
  • Bulk Operations: Batch processing with parallel support

๐Ÿ—„๏ธ Database Operations

  • Generic Repository Pattern: CRUD operations with Dapper
  • Query Builder: Dynamic SQL query construction
  • Connection Management: Database connection factory pattern
  • Unit of Work Pattern: Transaction management
  • Database Helper: Utility operations for database management

๐Ÿ“ Logging & Monitoring

  • Structured Logging: Serilog integration with console and file sinks
  • Performance Monitoring: Timer and statistics tracking
  • Health Checks: Database, API, and disk usage monitoring
  • Metrics Collection: Counters, gauges, and histograms

๐Ÿ“ File & Media Processing

  • Image Processing: Resize, format conversion, rotation, cropping with SixLabors.ImageSharp
  • File Compression: ZIP compression and decompression
  • Document Processing: Text-based document operations
  • Media Conversion: Base64, Hex, encoding, JSON/XML transformations

๐Ÿค– CAPTCHA & Anti-Bot

  • Google reCAPTCHA: v2/v3 integration
  • Math CAPTCHA: Customizable difficulty levels
  • CAPTCHA Manager: Unified management system
  • Configurable Options: Themes, languages, and expiration settings

๐Ÿงช Testing & Mocking Framework

  • Test Data Generation: Bogus integration for fake data
  • Mocking Support: Moq integration for test doubles
  • Assertion Helpers: Custom assertion methods
  • Test Base Classes: Common setup/teardown, performance measurement, database testing

Project Structure

WebLibrary/
โ”œโ”€โ”€ Global.cs                           # Global constants and configuration
โ”œโ”€โ”€ Models/
โ”‚   โ””โ”€โ”€ ServiceResult.cs                # Generic result wrapper
โ”œโ”€โ”€ Helpers/
โ”‚   โ”œโ”€โ”€ HttpClientHelper.cs             # HTTP client operations
โ”‚   โ””โ”€โ”€ ValidationHelper.cs             # Data validation
โ”œโ”€โ”€ Extensions/
โ”‚   โ””โ”€โ”€ GenericExtensions.cs            # Extension methods
โ”œโ”€โ”€ Utilities/
โ”‚   โ””โ”€โ”€ GenericUtilities.cs             # Utility methods
โ”œโ”€โ”€ Services/
โ”‚   โ””โ”€โ”€ GenericServiceBase.cs           # Base service class
โ”œโ”€โ”€ Security/
โ”‚   โ”œโ”€โ”€ JwtTokenHelper.cs               # JWT operations
โ”‚   โ”œโ”€โ”€ PasswordHelper.cs               # Password security
โ”‚   โ””โ”€โ”€ EncryptionHelper.cs             # Encryption utilities
โ”œโ”€โ”€ DataProcessing/
โ”‚   โ”œโ”€โ”€ CsvDataHelper.cs                # CSV operations
โ”‚   โ”œโ”€โ”€ ExcelHelper.cs                  # Excel operations
โ”‚   โ”œโ”€โ”€ DataTransformationHelper.cs     # Data transformation
โ”‚   โ””โ”€โ”€ BulkOperationsHelper.cs         # Bulk operations
โ””โ”€โ”€ Database/
    โ”œโ”€โ”€ IDbConnectionFactory.cs         # Connection factory interface
    โ”œโ”€โ”€ SqlServerConnectionFactory.cs   # SQL Server connection factory
    โ”œโ”€โ”€ QueryBuilder.cs                 # SQL query builder
    โ”œโ”€โ”€ IGenericRepository.cs           # Repository interface
    โ”œโ”€โ”€ DapperGenericRepository.cs      # Dapper repository implementation
    โ”œโ”€โ”€ IUnitOfWork.cs                  # Unit of work interface
    โ”œโ”€โ”€ UnitOfWork.cs                   # Unit of work implementation
    โ””โ”€โ”€ DatabaseHelper.cs               # Database utilities
โ”œโ”€โ”€ Logging/
    โ”œโ”€โ”€ StructuredLoggingHelper.cs      # Serilog structured logging
    โ”œโ”€โ”€ PerformanceMonitoringHelper.cs  # Performance tracking
    โ”œโ”€โ”€ HealthCheckHelper.cs            # Health checks
    โ””โ”€โ”€ MetricsCollectionHelper.cs      # Metrics collection
โ”œโ”€โ”€ FileMedia/
    โ”œโ”€โ”€ ImageProcessingHelper.cs        # Image manipulation
    โ”œโ”€โ”€ FileCompressionHelper.cs        # File compression
    โ”œโ”€โ”€ DocumentProcessingHelper.cs     # Document operations
    โ””โ”€โ”€ MediaConversionHelper.cs        # Media conversion
โ”œโ”€โ”€ Captcha/
    โ”œโ”€โ”€ ICaptchaProvider.cs             # CAPTCHA provider interface
    โ”œโ”€โ”€ GoogleRecaptchaProvider.cs      # Google reCAPTCHA
    โ”œโ”€โ”€ MathCaptchaProvider.cs          # Math CAPTCHA
    โ”œโ”€โ”€ CaptchaManager.cs               # CAPTCHA management
    โ””โ”€โ”€ CaptchaModels.cs                # CAPTCHA models
โ””โ”€โ”€ Testing/
    โ”œโ”€โ”€ TestDataGenerator.cs            # Fake data generation
    โ”œโ”€โ”€ MockHelper.cs                   # Mocking utilities
    โ”œโ”€โ”€ AssertionHelper.cs              # Custom assertions
    โ””โ”€โ”€ TestBase.cs                     # Test base classes

WebLibraryTest/                         # Test console application
โ””โ”€โ”€ Program.cs                          # Test implementation

Installation

NuGet Package

dotnet add package WebLibrary

Manual Installation

  1. Clone this repository
  2. Build the solution
  3. Reference the WebLibrary.dll in your project

Quick Start

Basic Usage

using WebLibrary.Models;
using WebLibrary.Helpers;

// Use ServiceResult for operation results
var result = ServiceResult<string>.Success("Operation completed");

// HTTP operations
var httpResult = await HttpClientHelper.GetAsync<MyModel>("https://api.example.com/data");

// Validation
bool isValidEmail = ValidationHelper.IsValidEmail("test@example.com");

Security Features

using WebLibrary.Security;

// JWT Token operations
var token = JwtTokenHelper.GenerateToken(claims, secretKey);
var isValid = JwtTokenHelper.ValidateToken(token, secretKey);

// Password hashing
var hashedPassword = PasswordHelper.HashPassword("mypassword");
var isValidPassword = PasswordHelper.VerifyPassword("mypassword", hashedPassword);

// Encryption
var encrypted = EncryptionHelper.AesEncrypt("sensitive data", key, iv);
var decrypted = EncryptionHelper.AesDecrypt(encrypted, key, iv);

Data Processing

using WebLibrary.DataProcessing;

// CSV operations
var csvResult = CsvDataHelper.WriteToCsv(data, "output.csv");
var readResult = CsvDataHelper.ReadFromCsv<MyModel>("input.csv");

// Excel operations
var excelResult = ExcelDataHelper.WriteToExcel(data, "output.xlsx");
var excelReadResult = ExcelDataHelper.ReadFromExcel<MyModel>("input.xlsx");

// Data transformation
var jsonResult = DataTransformationHelper.ToJson(myObject);
var dictResult = DataTransformationHelper.ToDictionary(myObject);

Database Operations

using WebLibrary.Database;

// Connection factory
var connectionFactory = new SqlServerConnectionFactory(connectionString);

// Repository pattern
public class UserRepository : DapperGenericRepository<User>
{
    public UserRepository(IDbConnectionFactory connectionFactory) 
        : base(connectionFactory, "Users") { }
}

// Query builder
var query = new QueryBuilder()
    .Select("Id", "Name", "Email")
    .From("Users")
    .Where("Age > @MinAge")
    .OrderBy("Name")

Logging & Monitoring

using WebLibrary.Logging;

// Structured logging
StructuredLoggingHelper.ConfigureLogger(Serilog.Events.LogEventLevel.Information, "logs/app.log");
StructuredLoggingHelper.LogInformation("User logged in: {UserId}", userId);

// Performance monitoring
PerformanceMonitoringHelper.StartTimer("api-call");
var result = await apiService.CallAsync();
PerformanceMonitoringHelper.StopTimer("api-call");

// Health checks
HealthCheckHelper.RecordHealthCheck("database", HealthStatus.Healthy, "Connection OK");
var systemHealth = HealthCheckHelper.GetSystemHealthStatus();

// Metrics collection
MetricsCollectionHelper.IncrementCounter("api-requests", 1);
MetricsCollectionHelper.SetGauge("active-users", 150);

File & Media Processing

using WebLibrary.FileMedia;

// Image processing
ImageProcessingHelper.ResizeImage("input.jpg", "output.jpg", 800, 600);
ImageProcessingHelper.ConvertImageFormat("input.jpg", "output.png", ImageFormat.PNG);

// File compression
FileCompressionHelper.CompressDirectory("source-folder", "archive.zip");
FileCompressionHelper.ExtractZip("archive.zip", "extract-folder");

// Media conversion
var base64 = MediaConversionHelper.ConvertFileToBase64("file.txt");
var hex = MediaConversionHelper.ConvertFileToHex("file.txt");

CAPTCHA & Anti-Bot

using WebLibrary.Captcha;

// Math CAPTCHA
var mathCaptcha = new MathCaptchaProvider();
var captchaResult = mathCaptcha.GenerateCaptcha(new CaptchaOptions
{
    Type = CaptchaType.MathCaptcha,
    Difficulty = CaptchaDifficulty.Medium,
    Language = "tr"
});

// Google reCAPTCHA
var googleCaptcha = new GoogleRecaptchaProvider(new GoogleRecaptchaSettings
{
    SiteKey = "your-site-key",
    SecretKey = "your-secret-key"
});

// CAPTCHA Manager
var captchaManager = new CaptchaManager();
var result = captchaManager.GenerateCaptcha(CaptchaType.MathCaptcha, options);

Testing & Mocking Framework

using WebLibrary.Testing;

// Test data generation
var users = TestDataGenerator.GenerateUsers(10);
var products = TestDataGenerator.GenerateProducts(5);

// Mocking
var mockRepo = MockHelper.CreateRepositoryMock<User>(users);
var mockLogger = MockHelper.CreateLoggerMock<MyService>();

// Assertions
AssertionHelper.IsNotNull(users);
AssertionHelper.HasCount(users, 10);
AssertionHelper.Contains(users, users.First());

// Test base classes
public class MyTestClass : TestBase
{
    protected override void SetupTestData()
    {
        // Test setup
    }
}
    .AddParameter("MinAge", 18)
    .Build();

// Unit of Work
using var unitOfWork = new UnitOfWork(connectionFactory);
var userRepo = unitOfWork.GetRepository<User, UserRepository>();
await unitOfWork.CommitAsync();

Dependencies

  • .NET 9.0
  • BCrypt.Net-Next 4.0.3
  • CsvHelper 33.1.0
  • Dapper 2.1.66
  • EPPlus 8.1.0
  • Microsoft.Data.SqlClient 6.1.1
  • System.IdentityModel.Tokens.Jwt 8.14.0

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

This project is licensed under the MIT License.

Updates

  • v1.0.0: Initial release with core components
  • v1.1.0: Added Security & Authentication features
  • v1.2.0: Added Data Processing features
  • v1.3.0: Added Database Operations with Dapper integration
  • v1.4.0: Added Logging & Monitoring, File & Media Processing, CAPTCHA & Anti-Bot, and Testing & Mocking Framework

Support

For issues and questions, please open an issue on GitHub.

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
1.5.0 114 8/19/2025
1.4.0 115 8/19/2025
1.3.0 110 8/19/2025