
A modular, production-ready C#/.NET utility library and toolkit for rapid development.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
CommonUtilities is a modular, production-ready C#/.NET utility library and toolkit designed to accelerate development for .NET 8+ projects. It provides a comprehensive set of helpers, models, and utilities for common application needs, including security, data, HTTP, scheduling, media, and more. The project is structured for easy extension and integration into any .NET solution.
- Security: AES, SHA256, 3DES, signature, and validation helpers
- Data: Conversion, formatting, JSON file operations
- HTTP: Basic and advanced HTTP utilities
- System: App settings, caching, file/process utilities, logging, timestamps
- Scheduler: Cron jobs, scheduled services, extensible SyncService base
- Media: Image processing helpers
- QR Code: QR code generation utilities
- Stripe: Payment integration helpers
- Google MFA: Multi-factor authentication helpers
- Cloudflare Captcha: Captcha validation helpers
- Mailer: SMTP and email sending helpers
- IP Info: IP geolocation and lookup helpers
- Command: Command-line helper utilities
- Enum: Enum parsing and conversion helpers
- Database: Strongly-typed models and DbContext
- Extensible: Modular, production-ready, and open source
- .NET 8.0
- C#
- xUnit.net (for testing)
- .NET Community Toolkit
To use CommonUtilities in your .NET project, follow these steps:
- .NET 8.0 SDK
- (Optional) xUnit.net for testing
- Clone the repository:
git clone https://github.com/LoveDoLove/CS_CommonUtilities.git
- Add the project or reference the compiled DLL in your solution.
- (Optional) Restore and run tests:
dotnet restore dotnet test
Many helpers require configuration via appsettings.json
(or appsettings.Development.json
). Example:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DBConnection": "Server=(localdb)\\mssqllocaldb;Database=NetCore-Mvc-Setup-Kit;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true"
},
"Smtp": {
"Host": "smtp.example.com",
"Port": 587,
"Username": "[email protected]",
"Password": "example",
"From": "[email protected]",
"Name": "example"
},
"CfCaptcha": {
"SiteKey": "xxx",
"SecretKey": "xxx"
},
"IpInfo": {
"Token": "xxx"
},
"Stripe": {
"ApiKey": "sk_test_xxx",
"WebhookSecret": "whsec_xxx"
}
}
- Adjust these values for your environment.
- For development, use
appsettings.Development.json
to override settings as needed. - See the sample files for all available options.
Import the relevant namespaces from CommonUtilities
and use the helpers as needed.
Basic Security Example:
using CommonUtilities.Utilities.Security;
string encrypted = AesUtilities.Encrypt("mydata", "password");
string hash = Sha256Utilities.ComputeHash("mydata");
MailerHelper with configuration:
using CommonUtilities.Helpers.Mailer;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var smtpConfig = config.GetSection("Smtp").Get<SmtpConfig>();
var mailer = new MailerHelper(smtpConfig);
await mailer.SendAsync("[email protected]", "Subject", "Body");
StripeHelper:
using CommonUtilities.Helpers.Stripe;
var stripeConfig = new StripeConfig { ApiKey = "sk_test_xxx" };
var stripe = new StripeHelper(stripeConfig);
// Use stripe methods for payment, customer, etc.
SyncService (scheduled job):
// Inherit from SyncServiceBase<T> and override ExecuteSyncAsync for your job logic.
For more usage examples, see the source code and XML documentation in each helper class.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
To contribute:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Please follow the Context7 and .NET Foundation code of conduct and best practices.
Distributed under the MIT License. See LICENSE
for more information.
LoveDoLove - GitHub
Project Link: https://github.com/LoveDoLove/CS_CommonUtilities