Skip to content

Installation

Classic Installation

AventusSharp is a C# library that can be installed in any .NET project using the following command:

Terminal window
dotnet add package AventusSharp

Alternatively, you can add it directly to your .csproj file:

<PackageReference Include="AventusSharp" Version="x.x.x" />

Creating a Blank Project

To set up a demo project using .NET 8.0, follow these steps:

  1. Create a new web project:

    Terminal window
    dotnet new web --name Demo
  2. Add the AventusSharp package:

    Terminal window
    dotnet add package AventusSharp
  3. Add the Newtonsoft.Json package:

    Terminal window
    dotnet add package Newtonsoft.Json

Setting up the Aventus Initialization File

Create a C# file called Aventus.cs to initialize the AventusSharp library:

Aventus.cs
using AventusSharp.Tools;
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();
// Enable Aventus routing in the app
app.Use(RouterMiddleware.OnRequest);
// Register all Aventus routes from the current project
initResult.Run(RouterMiddleware.Register);
return initResult;
}
}
}

Creating a “Hello World” Route

In another C# file named HelloWorld.cs, create a sample route that returns “Hello World”:

HelloWorld.cs
using AventusSharp.Routes.Response;
using AventusSharp.Routes;
namespace Demo
{
// Extends Router => this allows Aventus RouterMiddleware to use it
public class HelloWorld : Router
{
public string Index()
{
return "Hello World";
}
}
}

Using the Aventus Initialization File in Program.cs

Finally, update the Program.cs file to use the Aventus initialization:

Program.cs
using AventusSharp.Tools;
using Demo;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
if (app != null)
{
// Initialize Aventus
VoidWithError initResult = Aventus.Init(app);
if (initResult.Success)
{
// Start the app if initialization succeeds
app.Run();
}
else
{
// Print any errors to the console
initResult.Print();
}
}

Running the Development Server

To start the development server, use:

Terminal window
dotnet run

Then, navigate to the URL / in your browser to see “Hello World” displayed by your project.


Ready-to-Use Installation

If you’re using the Aventus extension in Visual Studio Code, you can quickly set up ready-to-use project templates:

  1. Download the templates from the Laraventus Project.

After completing this, you’ll be able to create new ready-to-use web applications tailored to your needs.