and since then lots of ASP.NET open source frameworks that build upon - and improve! - web development on .NET have become popular.
There's more than one way to serve and angle bracket (or curly brace) my friends!
Jonathan Channon and the .
One of the best things about ASP.NET Core is its extensibility model and Carter takes full advantage of that. Carter is ASP.NET.
You can add Carter to your existing ASP.NET Core app by just "dotnet add package carter" and adding it to your Startup.cs:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddCarter();
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(builder => builder.MapCarter());
}
}
At this point you can make a quick "microservice" - in this case just handle an HTTP GET - in almost no code, and it's super clear to read:
public class HomeModule : CarterModule
{
public HomeModule()
{
Get("/", async (req, res) => await res.WriteAsync("Hello from Carter!"));
}
}
Or you can add Carter as a template so you can later "dotnet new carter." Start by adding the Carter Template with "dotnet new -i CarterTemplate" and now you can make a new boilerplate starter app anytime.
There's a lot of great sample code on the and give them more Stars!
Carter can also cleanly integrate with your existing ASP.NET apps because, again, it's extensions and improvements on top of ASP.NET. Now how you can add Carter to a ASP.NET Core app that's using Controllers in the MVC pattern just like this:
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(builder =>
{
builder.MapDefaultControllerRoute();
builder.MapCarter();
});
}
Then easily handle a GET by returning a list of things as JSON like this:
this.Get<GetActors>("/actors", async (req, res) =>
{
var people = actorProvider.Get();
await res.AsJson(people);
});
Again, check out on Twitter!
Sponsor: Like C#? We do too! That’s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows.
SOCIAL SHARE CARD GENERATOR