StoneKit.Infrastructure 2024.1.1.261674

There is a newer version of this package available.
See the version list below for details.
dotnet add package StoneKit.Infrastructure --version 2024.1.1.261674                
NuGet\Install-Package StoneKit.Infrastructure -Version 2024.1.1.261674                
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="2024.1.1.261674" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StoneKit.Infrastructure --version 2024.1.1.261674                
#r "nuget: StoneKit.Infrastructure, 2024.1.1.261674"                
#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=2024.1.1.261674

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

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 (6)

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

Package Downloads
StoneKit.Trustee.Host

rtwert

StoneKit.Trustee.Providers.AzureKeyVault

Package Description

StoneKit.Trustee.Providers.FileSystem

Package Description

StoneKit.Trustee.Providers.HashicorpVault

Package Description

StoneKit.Trustee.Providers.Git

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.1.1.391401 78 10/5/2024
2024.1.1.305385 126 8/5/2024
2024.1.1.268769 99 7/9/2024
2024.1.1.261674 100 7/4/2024
2024.1.1.261665 96 7/4/2024
2024.1.1.261630 111 7/4/2024
2024.1.1.260673 111 7/3/2024
2024.1.1.260489 104 7/3/2024
2024.1.1.260485 98 7/3/2024
1.24.703.180801 474 7/3/2024
1.24.703.164607 351 7/3/2024
1.24.703.121215 183 7/3/2024
1.24.626.192714 86 6/26/2024
1.24.612.917 85 6/11/2024
1.24.611.233128 81 6/11/2024
1.24.611.232751 89 6/11/2024
1.24.603.121931 494 6/3/2024