Skip to content

Commit 0474a69

Browse files
authored
Merge pull request #379 from CarterCommunity/net10
.NET 10
2 parents 3c9b67b + 7fb1bf4 commit 0474a69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+814
-330
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,32 @@ jobs:
2525
- name: Setup .NET Core
2626
uses: actions/setup-dotnet@v2
2727
with:
28-
dotnet-version: 9.*
28+
dotnet-version: 10.*
29+
include-prerelease: true
30+
2931
- name: Build Reason
3032
run: echo ${{github.ref}} and ${{github.event_name}}
33+
3134
- name: Build with dotnet
3235
run: >-
3336
dotnet build
3437
--configuration Release
3538
--nologo
39+
3640
- name: Run tests
3741
run: >-
3842
dotnet test
3943
--configuration Release
4044
--logger trx
4145
--no-build
4246
--nologo
43-
- name: Publish test results
44-
uses: dorny/test-reporter@v1
47+
48+
- name: Upload test results
49+
uses: actions/upload-artifact@v4
4550
if: always()
4651
with:
47-
name: .NET tests
48-
path: '**/*.trx'
49-
reporter: dotnet-trx
52+
name: test-results
53+
path: '**/*.trx'
5054

5155
# PR merged or main tag created, create the CarterTemplate NuGet package
5256
- if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/newtonsoft-')

.github/workflows/test-results.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test Results
2+
3+
on:
4+
workflow_run:
5+
workflows: [".NET Core"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
test-results:
11+
name: Publish Test Results
12+
runs-on: ubuntu-latest
13+
if: always()
14+
permissions:
15+
contents: read
16+
actions: read
17+
checks: write
18+
19+
steps:
20+
- name: Publish test results
21+
uses: dorny/test-reporter@v2
22+
with:
23+
name: .NET tests
24+
artifact: test-results
25+
path: 'test-results/**/*.trx'
26+
reporter: dotnet-trx

Carter.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carter.ResponseNegotiators.
3434
EndProject
3535
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.Analyzers", "src\Carter.Analyzers\Carter.Analyzers.csproj", "{C15C71C0-73CE-41DA-8EEE-C66318BF3A6C}"
3636
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFwk", "samples\EntityFwk\EntityFwk.csproj", "{E907925B-A874-40EA-A7A8-0A41E462A465}"
38+
EndProject
3739
Global
3840
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3941
Debug|Any CPU = Debug|Any CPU
@@ -164,6 +166,18 @@ Global
164166
{C15C71C0-73CE-41DA-8EEE-C66318BF3A6C}.Release|x64.Build.0 = Release|Any CPU
165167
{C15C71C0-73CE-41DA-8EEE-C66318BF3A6C}.Release|x86.ActiveCfg = Release|Any CPU
166168
{C15C71C0-73CE-41DA-8EEE-C66318BF3A6C}.Release|x86.Build.0 = Release|Any CPU
169+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
170+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|Any CPU.Build.0 = Debug|Any CPU
171+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|x64.ActiveCfg = Debug|Any CPU
172+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|x64.Build.0 = Debug|Any CPU
173+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|x86.ActiveCfg = Debug|Any CPU
174+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Debug|x86.Build.0 = Debug|Any CPU
175+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|Any CPU.ActiveCfg = Release|Any CPU
176+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|Any CPU.Build.0 = Release|Any CPU
177+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|x64.ActiveCfg = Release|Any CPU
178+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|x64.Build.0 = Release|Any CPU
179+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|x86.ActiveCfg = Release|Any CPU
180+
{E907925B-A874-40EA-A7A8-0A41E462A465}.Release|x86.Build.0 = Release|Any CPU
167181
EndGlobalSection
168182
GlobalSection(SolutionProperties) = preSolution
169183
HideSolutionNode = FALSE
@@ -179,6 +193,7 @@ Global
179193
{D30E87B0-39AE-41FE-8BA3-E5F9FBFFDD64} = {5D056A8A-821C-4C3C-A281-4FA7F8CE251B}
180194
{47DD3AA8-F072-41E3-AF7F-119DBBD8D14A} = {DCB5B9A0-F06D-4BDF-917D-A459C790C718}
181195
{C15C71C0-73CE-41DA-8EEE-C66318BF3A6C} = {5D056A8A-821C-4C3C-A281-4FA7F8CE251B}
196+
{E907925B-A874-40EA-A7A8-0A41E462A465} = {35DE35A0-758D-4FDD-BDA3-67F04F65677D}
182197
EndGlobalSection
183198
GlobalSection(ExtensibilityGlobals) = postSolution
184199
SolutionGuid = {9096DE78-6327-48BA-AE0E-336F769681A7}

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Other extensions include:
88

99
* `Validate<T> / ValidateAsync<T>` - [FluentValidation](https://github.com/JeremySkinner/FluentValidation) extensions to validate incoming HTTP requests which is not available with ASP.NET Core Minimal APIs.
1010
* `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.
11-
* Routes to use in common ASP.NET Core middleware e.g., `app.UseExceptionHandler("/errorhandler");`.
11+
* `MapPost<T>/MapPut<T>` - Allows Carter to validate `T` and if it fails it returns a 422 Problem Details response.
12+
* `MapFormPost<T>` - Allows Carter to model bind `T` when submitting a form to the route.
1213
* `IResponseNegotiator`s 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.
14+
* Routes to use in common ASP.NET Core middleware e.g., `app.UseExceptionHandler("/errorhandler");`.
1315
* All interface implementations for Carter components are registered into ASP.NET Core DI automatically. Implement the interface and off you go.
1416

1517
### Releases
@@ -118,6 +120,7 @@ public class HomeModule : ICarterModule
118120
});
119121
app.MapGet("/conneg", (HttpResponse res) => res.Negotiate(new { Name = "Dave" }));
120122
app.MapPost("/validation", HandlePost);
123+
app.MapFormPost("/formpost", (Person model) => TypedResults.Ok(model)).DisableAntiforgery();
121124
}
122125

123126
private IResult HandlePost(HttpContext ctx, Person person, IDatabase database)
@@ -156,7 +159,7 @@ public class Database : IDatabase
156159

157160
### Configuration
158161

159-
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.
162+
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.
160163

161164
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`:
162165

@@ -166,16 +169,11 @@ Carter will use a response negotiator based on `System.Text.Json`, though it pro
166169
{
167170
c.WithResponseNegotiator<CustomResponseNegotiator>();
168171
c.WithModule<MyModule>();
169-
c.WithValidator<TestModelValidator>()
172+
c.WithValidator<TestModelValidator>();
173+
c.WithDefaultValidatorLifetime(ServiceLifetime.Singleton);
174+
c.WithValidatorServiceLifetimeFactory(t => {if t is PersonValidator...})
170175
});
171176

172177
```
173178

174-
Here again, Carter already ships with a response negotiator using `Newtonsoft.Json`, so you can wire up the Newtonsoft implementation with the following line:
175-
176-
```csharp
177-
builder.Services.AddCarter(configurator: c =>
178-
{
179-
c.WithResponseNegotiator<NewtonsoftJsonResponseNegotiator>();
180-
});
181-
```
179+
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.

samples/CarterAndMVC/CarterAndMVC.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<AssemblyName>CarterAndMVC</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<LangVersion>latest</LangVersion>

samples/CarterAndMVC/Program.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
namespace CarterAndMVC
2-
{
3-
using System.IO;
4-
using Microsoft.AspNetCore.Hosting;
1+
using Carter;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.DependencyInjection;
54

6-
public class Program
7-
{
8-
public static void Main(string[] args)
9-
{
10-
var host = new WebHostBuilder()
11-
.UseContentRoot(Directory.GetCurrentDirectory())
12-
.UseKestrel()
13-
.UseStartup<Startup>()
14-
.Build();
5+
var builder = WebApplication.CreateBuilder(args);
156

16-
host.Run();
17-
}
18-
}
19-
}
7+
builder.Services.AddCarter();
8+
builder.Services.AddControllers();
9+
10+
var app = builder.Build();
11+
12+
app.MapCarter();
13+
app.MapControllerRoute(
14+
name: "default",
15+
pattern: "{controller=Home}/{action=Index}/{id?}");
16+
17+
app.Run();

samples/CarterAndMVC/Startup.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

samples/CarterSample/CarterSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<ImplicitUsings>enable</ImplicitUsings>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77
<ItemGroup>

samples/CarterSample/Features/Actors/ActorValidator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace CarterSample.Features.Actors;
22

33
using FluentValidation;
44

5+
[ValidatorLifetimeAttribute(ServiceLifetime.Scoped)]
56
public class ActorValidator : AbstractValidator<Actor>
67
{
78
public ActorValidator()

samples/EntityFwk/EntityFwk.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<NoDefaultLaunchSettingsFile>True</NoDefaultLaunchSettingsFile>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\src\Carter\Carter.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0-rc.1.25451.107" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0-rc.1.25451.107">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0-rc.1.25451.107" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)