Configuration
By convention, the configuration for AventusSharp is managed in a file named Aventus.cs
located at the root of your project. This file must include a public static Init(...)
method that returns a VoidWithError
, indicating whether Aventus successfully started.
Depending on your requirements, you can create functions within Aventus.cs
to configure and initialize each component individually. Below is an example structure of the Aventus.cs
file with each configuration section included. The order in which these functions are called does not matter.
For each configuration section, you’ll find specific documentation detailing the available options.
Example Code for Aventus.cs
using AventusSharp.Data;using AventusSharp.Tools;using AventusSharp.WebSocket;using RouterMiddleware = AventusSharp.Routes.RouterMiddleware;
namespace Demo{ public static class Aventus { public static VoidWithError Init(WebApplication app) { // This object handles errors without throwing exceptions VoidWithError initResult = new();
// Initialize each component InitData(initResult); InitHttp(initResult, app); InitWs(initResult, app);
return initResult; }
private static void InitData(VoidWithError initResult) { // Configure DataMainManager here DataMainManager.Configure((config) => { // Add your data configuration settings here });
// Initialize the data manager asynchronously initResult.RunAsync(DataMainManager.Init); }
private static void InitHttp(VoidWithError initResult, WebApplication app) { // Configure RouterMiddleware here RouterMiddleware.Configure((config) => { // Add your HTTP routing settings here });
// Register routes and enable HTTP request handling initResult.Run(RouterMiddleware.Register); app.Use(RouterMiddleware.OnRequest); }
private static void InitWs(VoidWithError initResult, WebApplication app) { // Configure WebSocketMiddleware here WebSocketMiddleware.Configure((config) => { // Add your WebSocket configuration here });
// Register WebSocket routes and enable WebSocket request handling initResult.Run(WebSocketMiddleware.Register); app.Use(WebSocketMiddleware.OnRequest); } }}
This example file shows how to set up data management, HTTP routing, and WebSocket handling within AventusSharp. Each configuration block includes a Configure
method where specific settings can be defined.
For detailed configuration options for each section, refer to the documentation associated with each component.