![]() |
VOOZH | about |
dotnet add package Carter --version 10.0.0
NuGet\Install-Package Carter -Version 10.0.0
<PackageReference Include="Carter" Version="10.0.0" />
<PackageVersion Include="Carter" Version="10.0.0" />Directory.Packages.props
<PackageReference Include="Carter" />Project file
paket add Carter --version 10.0.0
#r "nuget: Carter, 10.0.0"
#:package Carter@10.0.0
#addin nuget:?package=Carter&version=10.0.0Install as a Cake Addin
#tool nuget:?package=Carter&version=10.0.0Install as a Cake Tool
Carter is a framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing the code to be more explicit and most importantly more enjoyable.
For a better understanding, take a good look at the samples inside this repo. The samples demonstrate usages of elegant extensions around common ASP.NET Core types as shown below.
Other extensions include:
Validate<T> / ValidateAsync<T> - FluentValidation extensions to validate incoming HTTP requests which is not available with ASP.NET Core Minimal APIs.BindFile/BindFiles/BindFileAndSave/BindFilesAndSave - Allows you to easily get access to a file/files that has been uploaded. Alternatively you can call BindFilesAndSave and this will save it to a path you specify.MapPost<T>/MapPut<T> - Allows Carter to validate T and if it fails it returns a 422 Problem Details response.MapFormPost<T> - Allows Carter to model bind T when submitting a form to the route.IResponseNegotiators allow you to define how the response should look on a certain Accept header(content negotiation). Handling JSON is built in the default response but implementing an interface allows the user to choose how they want to represent resources.app.UseExceptionHandler("/errorhandler");.Carter uses IEndpointRouteBuilder routing and all the extensions IEndpointConventionBuilder offers also known as Minimal APIs. For example you can define a route with authorization required like so:
app.MapGet("/", () => "There's no place like 127.0.0.1").RequireAuthorization();
I have been a huge fan of, and core contributor to Nancy, the best .NET web framework, for many years, and the name "Nancy" came about due to it being inspired from Sinatra the Ruby web framework. Frank Sinatra had a daughter called Nancy and so that's where it came from.
I was also trying to think of a derivative name, and I had recently listened to the song Empire State of Mind where Jay-Z declares he is the new Sinatra. His real name is Shaun Carter so I took Carter and here we are!
If you'd like to try the latest builds from the master branch add https://f.feedz.io/carter/carter/nuget/index.json to your NuGet.config and pick up the latest and greatest version of Carter.
You can get started using either the template or by adding the package manually to a new or existing application.
https://www.nuget.org/packages/CarterTemplate/
Install the template - dotnet new install CarterTemplate
Create a new application using template - dotnet new carter -n MyCarterApp -o MyCarterApp
Go into the new directory created for the application cd MyCarterApp
Run the application - dotnet run
https://www.nuget.org/packages/Carter
Create a new empty ASP.NET Core application - dotnet new web -n MyCarterApp
Change into the new project location - cd ./MyCarterApp
Add Carter package - dotnet add package carter
Modify your Program.cs to use Carter
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCarter();
var app = builder.Build();
app.MapCarter();
app.Run();
public class HomeModule : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/", () => "Hello from Carter!");
}
}
dotnet runvar builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IActorProvider, ActorProvider>();
builder.Services.AddCarter();
var app = builder.Build();
app.MapCarter();
app.Run();
public class HomeModule : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/", () => "Hello from Carter!");
app.MapGet("/qs", (HttpRequest req) =>
{
var ids = req.Query.AsMultiple<int>("ids");
return $"It's {string.Join(",", ids)}";
});
app.MapGet("/conneg", (HttpResponse res) => res.Negotiate(new { Name = "Dave" }));
app.MapPost("/validation", HandlePost);
app.MapFormPost("/formpost", (Person model) => TypedResults.Ok(model)).DisableAntiforgery();
}
private IResult HandlePost(HttpContext ctx, Person person, IDatabase database)
{
var result = ctx.Request.Validate(person);
if (!result.IsValid)
{
return Results.UnprocessableEntity(result.GetFormattedErrors());
}
var id = database.StorePerson(person);
ctx.Response.Headers.Location = $"/{id}";
return Results.StatusCode(201);
}
}
public record Person(string Name);
public interface IDatabase
{
int StorePerson(Person person);
}
public class Database : IDatabase
{
public int StorePerson(Person person)
{
//db stuff
}
}
As mentioned earlier Carter will scan for implementations in your app and register them for DI. However, if you want a more controlled app, Carter comes with a CarterConfigurator that allows you to register modules, validators and response negotiators manually and configure validator lifetimes.
Carter will use a response negotiator based on System.Text.Json, though it provides for custom implementations via the IResponseNegotiator interface. To use your own implementation of IResponseNegotiator (say, CustomResponseNegotiator), add the following line to the initial Carter configuration, in this case as part of Program.cs:
builder.Services.AddCarter(configurator: c =>
{
c.WithResponseNegotiator<CustomResponseNegotiator>();
c.WithModule<MyModule>();
c.WithValidator<TestModelValidator>();
c.WithDefaultValidatorLifetime(ServiceLifetime.Singleton);
c.WithValidatorServiceLifetimeFactory(t => {if t is PersonValidator...})
});
If you wish to use Newtonsoft.Json Carter already ships a response negotiator in the package Carter.ResponseNegotiators.Newtonsoft. Once installed, it will automatically pick it up with no registration needed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Carter:
| Package | Downloads |
|---|---|
|
Carter.ResponseNegotiators.Newtonsoft
Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable. |
|
|
SpCraft.Net.Common.Api
Package Description |
|
|
Linn.Common.Facade.Carter
Package Description |
|
|
SMGJ.Common
SMGJ Common library package |
|
|
Carter.SirenNegotiator
A library to extend Carter to handle the siren hypermedia media type. |
Showing the top 17 popular GitHub repositories that depend on Carter:
| Repository | Stars |
|---|---|
|
aspnetrun/run-aspnetcore-microservices
Microservices on .NET platforms used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
|
|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
|
aliostad/CacheCow
An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
|
|
|
featherhttp/framework
A lightweight low ceremony API for web services.
|
|
|
Particular/Workshop
SOA Done Right
|
|
|
mcneel/compute.rhino3d
REST geometry server based on RhinoCommon and headless Rhino
|
|
|
TanvirArjel/CleanArchitecture
This repository contains the implementation of domain-driven design and clear architecture in ASP.NET Core.
|
|
|
asc-lab/better-code-with-ddd
This repository contains code that accompanies presentation ASC LAB team gave at meetup about โCreating better code with Domain Driven Designโ.
|
|
|
poorna-soysa/grpc-demo
This repository contains a sample application built with .NET 8, demonstrating the use of gRPC for high-performance remote procedure calls
|
|
|
poorna-soysa/vertical-slice-architecture-template
Vertical Slice Architecture Template for .NET 10
|
|
|
poorna-soysa/url-shortener-app
This repository contains a n URL Shortener sample application built with .NET 10 , NET Aspire, PostgreSQL
|
|
|
thisisnabi/DigitalWallet
The E-Commerce User Wallet Service designed in ASP.NET Core
|
|
|
isaacOjeda/MinimalApiArchitecture
.NET 8 Minimal API with Vertical Slice Architecture
|
|
| mehmetozkaya/EShopMicroservices | |
|
thisisnabi/Notify
Notify as a service in ASP.NET Core & VSA
|
|
|
mehmetozkaya/EshopModularMonoliths
Modular Monoliths on .NET used ASP.NET Web API, Docker, PostgreSQL, Redis, RabbitMQ, Keycloak, Seq, MassTransit, Entity Framework Core, CQRS, MediatR, DDD, Vertical Slice Architecture and Outbox pattern implementation with using latest features of .NET 8 and C# 12
|
|
|
mehmetozkaya/EShopMicroservices-Udemy-Sections
This repository prepared for Udemy course sections that you can find all codes section-by-section on my Udemy Course
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 355,474 | 11/13/2025 |
| 9.0.0 | 567,012 | 11/16/2024 |
| 8.2.1 | 1,069,372 | 6/6/2024 |
| 8.2.0 | 35,733 | 5/24/2024 |
| 8.1.0 | 240,981 | 5/11/2024 |
| 8.0.0 | 558,507 | 12/4/2023 |
| 7.2.0 | 117,013 | 9/21/2023 |
| 7.1.0 | 150,047 | 4/22/2023 |
| 7.0.1 | 22,165 | 3/15/2023 |
| 7.0.0 | 45,768 | 11/21/2022 |
| 7.0.0-beta | 380 | 11/21/2022 |
| 7.0.0-alpha1 | 321 | 11/18/2022 |
| 6.1.1 | 166,991 | 7/20/2022 |
| 6.1.0 | 4,538 | 7/15/2022 |
| 6.0.0 | 142,693 | 11/22/2021 |
| 6.0.0-rc4 | 1,862 | 11/12/2021 |
| 6.0.0-rc3 | 642 | 11/2/2021 |
| 6.0.0-rc2 | 532 | 10/25/2021 |