Installation
Classic Installation
AventusSharp is a C# library that can be installed in any .NET project using the following command:
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:
-
Create a new web project:
Terminal window dotnet new web --name Demo -
Add the AventusSharp package:
Terminal window dotnet add package AventusSharp -
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:
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”:
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:
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:
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:
- 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.