Carter 11.0.0
dotnet add package Carter --version 11.0.0
NuGet\Install-Package Carter -Version 11.0.0
<PackageReference Include="Carter" Version="11.0.0" />
<PackageVersion Include="Carter" Version="11.0.0" />
<PackageReference Include="Carter" />
paket add Carter --version 11.0.0
#r "nuget: Carter, 11.0.0"
#:package Carter@11.0.0
#addin nuget:?package=Carter&version=11.0.0
#tool nuget:?package=Carter&version=11.0.0
Carter
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 callBindFilesAndSaveand this will save it to a path you specify.MapPost<T>/MapPut<T>- Allows Carter to validateTand if it fails it returns a 422 Problem Details response.MapFormPost<T>- Allows Carter to model bindTwhen 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.- Routes to use in common ASP.NET Core middleware e.g.,
app.UseExceptionHandler("/errorhandler");. - All interface implementations for Carter components are registered into ASP.NET Core DI automatically. Implement the interface and off you go.
Releases
Join our Slack Channel
Routing
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();
Where does the name "Carter" come from?
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!
CI Builds
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.
Getting Started
You can get started using either the template or by adding the package manually to a new or existing application.
Template
https://www.nuget.org/packages/CarterTemplate/
Install the template -
dotnet new install CarterTemplateCreate a new application using template -
dotnet new carter -n MyCarterApp -o MyCarterAppGo into the new directory created for the application
cd MyCarterAppRun the application -
dotnet run
Package
https://www.nuget.org/packages/Carter
Create a new empty ASP.NET Core application -
dotnet new web -n MyCarterAppChange into the new project location -
cd ./MyCarterAppAdd Carter package -
dotnet add package carterModify your Program.cs to use Carter
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCarter();
var app = builder.Build();
app.MapCarter();
app.Run();
- Create a new Module
public class HomeModule : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/", () => "Hello from Carter!");
}
}
- Run the application -
dotnet run
Sample
var 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
}
}
Configuration
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.
Single file publishing
Carter normally finds your modules, validators and response negotiators by reading your app's .deps.json file. That file is not available to apps published with PublishSingleFile, so Carter instead walks the assembly references of your app, starting at the entry assembly, and scans the assemblies that reference Carter or FluentValidation. Assemblies whose names start with System. or Microsoft. are not walked.
The compiler removes references to assemblies whose types are never used in your code, so a project that is only referenced for its modules or validators will not be found this way. In that case, or if you want full control over what is scanned, pass the assemblies in yourself:
builder.Services.AddCarter(new DependencyContextAssemblyCatalog(typeof(Program).Assembly, typeof(MyValidator).Assembly));
Pass at least two assemblies, or an Assembly[]. A single assembly is treated as the entry assembly to discover from, not as the complete list to scan.
Trimmed and Native AOT publishing are not supported, as Carter discovers these types using reflection.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Carter.Analyzers (>= 11.0.0)
- FluentValidation (>= 12.2.0)
- Microsoft.Extensions.DependencyModel (>= 11.0.0)
NuGet packages (23)
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 |
|
|
SMGJ.Common
SMGJ Common library package |
|
|
Linn.Common.Facade.Carter
Package Description |
|
|
NexusLabs.Needlr.Carter
Package Description |
GitHub repositories (18)
Showing the top 18 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
Source code for 800+ C# and .NET articles from code-maze.com. Every article is a runnable solution, most with tests.
|
|
|
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
|
|
|
amasen02/freshcart-backend
FreshCart — .NET 10 + Aspire microservices reference e-commerce platform with an Angular 20 SPA
|
|
|
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 |
|---|---|---|
| 11.0.0 | 0 | 11/12/2026 |
| 10.0.0 | 1,229,988 | 11/13/2025 |
| 9.0.0 | 740,850 | 11/16/2024 |
| 8.2.1 | 1,308,217 | 6/6/2024 |
| 8.2.0 | 41,186 | 5/24/2024 |
| 8.1.0 | 266,315 | 5/11/2024 |
| 8.0.0 | 648,246 | 12/4/2023 |
| 7.2.0 | 124,918 | 9/21/2023 |
| 7.1.0 | 154,027 | 4/22/2023 |
| 7.0.1 | 23,868 | 3/15/2023 |
| 7.0.0 | 49,535 | 11/21/2022 |
| 7.0.0-beta | 419 | 11/21/2022 |
| 7.0.0-alpha1 | 356 | 11/18/2022 |
| 6.1.1 | 171,730 | 7/20/2022 |
| 6.1.0 | 5,143 | 7/15/2022 |
| 6.0.0 | 147,586 | 11/22/2021 |
| 6.0.0-rc4 | 1,967 | 11/12/2021 |
| 6.0.0-rc3 | 675 | 11/2/2021 |
