Skip to content

LoveDoLove/CS_CommonUtilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

CommonUtilities

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
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

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.

Features

  • 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

(back to top)

Built With

(back to top)

Getting Started

To use CommonUtilities in your .NET project, follow these steps:

Prerequisites

Installation

  1. Clone the repository:
    git clone https://github.com/LoveDoLove/CS_CommonUtilities.git
  2. Add the project or reference the compiled DLL in your solution.
  3. (Optional) Restore and run tests:
    dotnet restore
    dotnet test

Configuration

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.

(back to top)

Usage

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.

(back to top)

Contributing

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:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please follow the Context7 and .NET Foundation code of conduct and best practices.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

LoveDoLove - GitHub

Project Link: https://github.com/LoveDoLove/CS_CommonUtilities

(back to top)

Acknowledgments

(back to top)