FortiCore 1.0.2

dotnet add package FortiCore --version 1.0.2
                    
NuGet\Install-Package FortiCore -Version 1.0.2
                    
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="FortiCore" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FortiCore" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="FortiCore" />
                    
Project file
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 FortiCore --version 1.0.2
                    
#r "nuget: FortiCore, 1.0.2"
                    
#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 FortiCore@1.0.2
                    
#: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=FortiCore&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=FortiCore&version=1.0.2
                    
Install as a Cake Tool

FortiCore Library

FortiCore is a .NET library that provides core functionality for building robust web applications with features like logging, validation, and exception handling. This solution includes both the core library and a test API project.

🚀 Features

Core Library Features

  • MediatR Integration - Built-in CQRS pattern support
  • Logging System
    • Elasticsearch integration
    • Request/Response logging
    • Exception logging
    • Reference ID tracking
  • Validation Framework - FluentValidation integration
  • Exception Handling - Centralized error management
  • Response Standardization - Consistent API responses
  • Core Controllers
    • Base controller implementation
    • Standardized HTTP response handling
    • Common controller functionality

🛠 Technology Stack

  • .NET 8.0
  • MediatR 12.4.1
  • FluentValidation
  • Elasticsearch
  • NEST 7.17.5
  • Serilog 4.0
  • Docker & Docker Compose

📦 Installation

  1. Clone the repository
  2. Build the solution:
dotnet build
  1. Run the Elasticsearch and Kibana containers:
docker-compose up -d

🔧 Configuration

Elasticsearch Setup

The default configuration connects to:

  • Elasticsearch: http://localhost:9200
  • Kibana: http://localhost:5601

You can customize Elasticsearch connection settings using one of the following methods:

Method 1: Using ConfigureElasticsearch
// Configure during startup in Program.cs
builder.Services.AddDependencies(typeof(Program).Assembly);

// Configure Elasticsearch settings from configuration
builder.Services.ConfigureElasticsearch(options => 
{
    options.ConnectionString = builder.Configuration["ElasticSearch:ConnectionString"];
    options.IndexName = builder.Configuration["ElasticSearch:IndexName"];
});
Method 2: Using LogWriterFactory
// Inject LogWriterFactory and create custom log writer instances
public class YourService
{
    private readonly ILogWriter _logWriter;

    public YourService(LogWriterFactory logWriterFactory, IConfiguration configuration)
    {
        // Create custom LogWriter with specific Elasticsearch settings
        _logWriter = logWriterFactory.CreateLogWriter(
            configuration["ElasticSearch:ConnectionString"],
            configuration["ElasticSearch:IndexName"]
        );
    }
}
Configure in appsettings.json
{
  "ElasticSearch": {
    "ConnectionString": "http://your-elasticsearch-server:9200",
    "IndexName": "your-application-index"
  }
}

Logging Configuration

Logs are automatically sent to Elasticsearch with the following information:

  • Timestamp
  • Log Level
  • Method Information
  • Request/Response Data
  • Execution Time
  • Reference ID

💡 Usage Examples

Adding FortiCore to Your Project

// Register FortiCore dependencies
builder.Services.AddDependencies(typeof(Program).Assembly);

// Optionally configure Elasticsearch
builder.Services.ConfigureElasticsearch(options => 
{
    options.ConnectionString = "http://your-elasticsearch-server:9200";
    options.IndexName = "your-custom-index";
});

Creating a Query Handler

public class UserInformationQueryHandler : IRequestHandler<UserInformationQuery, UserInformationQueryResult>
{
    public async Task<UserInformationQueryResult> Handle(UserInformationQuery request, 
        CancellationToken cancellationToken)
    {
        return new UserInformationQueryResult() { Users = list }.ToSuccessResult();
    }
}

Using BaseController

The BaseController is located in FortiCore.Core.Controllers namespace and provides a standardized way to handle HTTP responses in your API controllers.

using FortiCore.Core.Controllers;

public class YourController : BaseController
{
    public IActionResult YourAction()
    {
        var response = new ApiResponse<YourData>();
        // ... your logic here ...
        return CreateResponse(response);
    }
}

The BaseController provides:

  • Standardized response handling through CreateResponse<T> method
  • Automatic HTTP status code mapping (200 for success, 400 for failure)
  • Integration with FortiCore's response models

🔐 License

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

👥 Contributors

  • Cuneyt Serdaroglu

📫 Support

For support, please open an issue in the repository.

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.  net9.0 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 285 3/23/2025
1.0.1 161 3/19/2025
1.0.0 177 3/9/2025