- Published on
Minimal Api with ABP - Hello World - Part 1
Table of Contents
Intro
Minimal api in .Net 6 provides a new way for creating http api. Minimal API provides simplicity and removes lot of boilerplate. We will see how to use the minimal api with ABP.
Hello world
First lets create a empty c# project.
dotnet new web -n HelloWorld
This will create a empty hello world project.
Let add the abp packages.
dotnet add package Volo.Abp.Autofac
dotnet add package Volo.Abp.AspNetCore.Mvc
Minimal Module
lets create a very simple module.
[DependsOn(
typeof(AbpAspNetCoreMvcModule),
typeof(AbpAutofacModule)
)]
public class MinimalModule : AbpModule
{
}
This module depends on AbpAspNetCoreMvcModule and AbpAutofacModule. The configure service method is used to register the assembly of MinimalModule for dependency injection.
Hello service
lets create a simple service which will say hello world.
public class HelloService : ITransientDependency
{
public string SayHi()
{
return "Hi from service";
}
}
Minimal Application
Lets create the minimal application
using Volo.Abp;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseAutofac();
builder.Services.ReplaceConfiguration(builder.Configuration);
builder.Services.AddApplication<MinimalModule>();
var app = builder.Build();
app.MapGet("/hi", ([FromServices] HelloService helloService) =>
{
return helloService.SayHi();
});
app.InitializeApplication();
app.Run();
This application has only one end point /hi which prints hello world. We are Injecting the hello world service we created and then we are calling the SayHi method from the service.
To run the app.
dotnet run
Related Posts
Continue reading with these related articles
Introducing SimpleModule: A Modular Monolith Framework for .NET 10
Meet SimpleModule, an experimental .NET 10 framework that uses Roslyn source generators to build modular monoliths with compile-time module discovery, full-stack type safety, and Inertia.js-powered React UIs.
Migrating an ABP Frontend from Next.js to TanStack Start
A real-world case study of moving abp-react from Next.js App Router to TanStack Start — what changed in routing, SSR, OIDC, the generated API client, state, and Docker.
Building AI-Powered Sentiment Analysis with Microsoft Agent Framework and Ollama
Learn how to build sentiment analysis with Microsoft Agent Framework and Ollama. We will use the Ollama model to perform the sentiment analysis and the Microsoft Agent Framework to build the agent.