StoneKit.Infrastructure 1.24.612.917

dotnet add package StoneKit.Infrastructure --version 1.24.612.917
NuGet\Install-Package StoneKit.Infrastructure -Version 1.24.612.917
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="StoneKit.Infrastructure" Version="1.24.612.917" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StoneKit.Infrastructure --version 1.24.612.917
#r "nuget: StoneKit.Infrastructure, 1.24.612.917"
#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.
// Install StoneKit.Infrastructure as a Cake Addin
#addin nuget:?package=StoneKit.Infrastructure&version=1.24.612.917

// Install StoneKit.Infrastructure as a Cake Tool
#tool nuget:?package=StoneKit.Infrastructure&version=1.24.612.917

StoneKit Infrastructure

StoneKit Infrastructure is a comprehensive boilerplate for starting new ASP.NET Core 8 API projects. It integrates essential libraries and services, including FluentValidation, Serilog logging, hashing, HttpClient, OpenAPI documentation, and more, to streamline the setup and development process.

Installation

You can install StoneKit.Infrastructure via NuGet Package Manager:

PM> Install-Package StoneKit.Infrastructure

Features

  • Logging:

    • Integrates Serilog for robust and flexible logging.
  • Validation:

    • Incorporates FluentValidation for model validation.
  • Hashing:

    • Provides hashing utilities for secure data hashing.
  • HTTP Client:

    • Configures HttpClient for making HTTP requests.
  • OpenAPI Documentation:

    • Configures Swagger and SwaggerUI for API documentation.
  • CORS Configuration:

    • Allows easy setup of CORS policies.
  • Middleware:

    • Includes custom middleware for exception handling and initialization.
    • Adds various security-related middlewares (e.g., no-cache headers, redirect validation).
  • SignalR:

    • Configures SignalR with environment-specific settings.
  • Dependency Injection:

    • Registers necessary services and middlewares for dependency injection.
  • Controller Configuration:

    • Sets up controllers with Newtonsoft.Json for JSON serialization.
  • Security:

    • Adds multiple security headers and policies.

Usage

Setting up your project

  1. Configure Services:

    In your Program.cs, use the ConfigureServices method to configure all necessary services.

    using Microsoft.Extensions.Configuration;
    
    var builder = WebApplication.CreateBuilder(args);
    
    var configOptions = new AppConfigurationOptions
    {
        // Set your options here
    };
    
    builder.ConfigureServices(configOptions);
    
    var app = builder.BuildApp(configOptions);
    
    app.Run();
    
  2. App Configuration Options:

    Define your configuration options to customize the setup.

    public class AppConfigurationOptions : BaseConfiguration
    {
        // Define properties like AppName, SerilogOptions, OpenApiOptions, etc.
    }
    
  3. FluentValidation:

    Add validators to your project by inheriting from AbstractValidator<T> and ensure they are in the configured assembly.

    using FluentValidation;
    
    public class SampleModelValidator : AbstractValidator<SampleModel>
    {
        public SampleModelValidator()
        {
            RuleFor(x => x.Property).NotEmpty();
        }
    }
    

Example Middleware

public class ExceptionHandlerMiddleware : IMiddleware
{
    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        try
        {
            await next(context);
        }
        catch (Exception ex)
        {
            // Handle exception
        }
    }
}

Adding Hashing Utility

public interface IHasher
{
    string Hash(string input);
}

public class Hasher : IHasher
{
    public string Hash(string input)
    {
        using var sha256 = SHA256.Create();
        var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(input));
        return Convert.ToBase64String(bytes);
    }
}

Configuring OpenAPI

public static void ConfigureOpenApi(this WebApplicationBuilder builder, string appName, OpenApiOptions options, Assembly validatorAssembly)
{
    // OpenAPI configuration logic
}

Contributions

Contributions and feedback are welcome! Feel free to submit issues, feature requests, or pull requests on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on StoneKit.Infrastructure:

Package Downloads
StoneKit.Trustee.Host

rtwert

StoneKit.Trustee

qeq er

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.24.612.917 64 6/11/2024
1.24.611.233128 57 6/11/2024
1.24.611.232751 63 6/11/2024
1.24.603.121931 201 6/3/2024