- 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
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.
Building AI Agents with Microsoft Agent Framework and Ollama: A Getting Started Guide
Learn how to build sophisticated AI agents using Microsoft Agent Framework with Ollama for local AI model execution. This comprehensive guide covers streaming responses, multi-turn conversations, function tools, middleware integration, and production-ready patterns.
ABP React CMS Module: Building Dynamic Pages with Puck Editor
ABP React CMS Kit is a React UI for the ABP CmsKit module.