-
Notifications
You must be signed in to change notification settings - Fork 0
Home
LittleBlocks is a set of libraries that facilitate different aspects of a Restful/Microservice API and takes away the boilerplate configuration/bootstrap code that needs to be written each time a new API project is a setup. There are up's and down's to this approach, however, the benefit of this approach is to set up consistent API projects faster and easier.
Boilerplate API provides the following features:
- Global Error Handling
- Preconfigured Logging to a rolling file and log aggregators such as Loggly and seq
- Application/Common services preregistration within IOC container
- Hosting as IIS or Windows Service
- Request Correlation
- Preconfigured MVC pipeline
- FluentValidation framework integration
- AutoMapper integration with desired IOC container
- RestEase REST client integration
- Open API integration
- Health endpoint exposed
- Diagnostics endpoint
- Observability
For using the full benefit of the library, Create a simple asp.net core project and install LittleBlocks.AspNetCore.Bootstrap NuGet package.
dotnet add package LittleBlocks.AspNetCore.Bootstrap
or
Install-Package LittleBlocks.AspNetCore.Bootstrap
In order to achieve all of this functionality you merely need a few lines of code. At this point your Program.cs should look like this:
public class Program
{
public static void Main(string[] args)
{
HostAsWeb.Run<Startup>(s => s.ConfigureLogger<Startup>());
}
}
And startup.cs as follows:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
private IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.BootstrapApp<Startup>(Configuration,
app => app
.HandleApplicationException<TemplateApiApplicationException>()
.AddServices((container, config) => { })
);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDefaultApiPipeline(Configuration, env, loggerFactory);
}
}
The project/solution is ready to be running in visual studio or using dotnet cli.
As you may see there are quite a few features enabled with very few lines of code. Let us take a deeper look at the template and let see what else it offers. Here is a list of topics we will be discussing in detail, so please feel free to skip to any section you maybe interested in:
- Configuration API
- Logging
- Hosting
- Exception Handling
- Object Mapping
- Validation
- Request Correlation
- REST Client
- Cors
- IOC
- Authentication
- API Documentation
- Testing
- Observability
Also, there are a couple of useful interfaces, tools, and utilities which you can use which they are already available in the framework.