FortiCore 1.0.2
dotnet add package FortiCore --version 1.0.2
NuGet\Install-Package FortiCore -Version 1.0.2
<PackageReference Include="FortiCore" Version="1.0.2" />
<PackageVersion Include="FortiCore" Version="1.0.2" />
<PackageReference Include="FortiCore" />
paket add FortiCore --version 1.0.2
#r "nuget: FortiCore, 1.0.2"
#:package FortiCore@1.0.2
#addin nuget:?package=FortiCore&version=1.0.2
#tool nuget:?package=FortiCore&version=1.0.2
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
- Clone the repository
- Build the solution:
dotnet build
- 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 | Versions 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. |
-
net8.0
- FluentValidation.DependencyInjectionExtensions (>= 12.0.0-preview1)
- MediatR (>= 12.4.1)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.Logging (>= 8.0.1)
- NEST (>= 7.17.5)
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 4.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.