TurgayAcar.WebLibrary
1.4.0
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="TurgayAcar.WebLibrary" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=TurgayAcar.WebLibrary&version=1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- Clone this repository
- Build the solution
- 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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- 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 | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- BCrypt.Net-Next (>= 4.0.3)
- Bogus (>= 35.6.3)
- CsvHelper (>= 33.1.0)
- Dapper (>= 2.1.66)
- EPPlus (>= 8.1.0)
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.Data.SqlClient (>= 6.1.1)
- Microsoft.Extensions.Configuration (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection (>= 9.0.8)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.8)
- Microsoft.Extensions.Logging (>= 9.0.8)
- Moq (>= 4.20.72)
- reCAPTCHA.AspNetCore (>= 3.0.10)
- Serilog (>= 4.3.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 7.0.0)
- SixLabors.ImageSharp (>= 3.1.11)
- System.IdentityModel.Tokens.Jwt (>= 8.14.0)
- System.IO.Compression (>= 4.3.0)
- System.Security.Cryptography.ProtectedData (>= 9.0.8)
- System.Text.Json (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.