Skip to content

modernize ASP.NET Core samples#326

Open
erwinkramer wants to merge 14 commits intocloudevents:mainfrom
erwinkramer:main
Open

modernize ASP.NET Core samples#326
erwinkramer wants to merge 14 commits intocloudevents:mainfrom
erwinkramer:main

Conversation

@erwinkramer
Copy link

@erwinkramer erwinkramer commented Mar 13, 2026

This modernizes the ASP.NET Core samples in a couple of ways:

  1. Minimal API's instead of controllers
  2. slnx instead of sln solution
  3. ASP.NET Core 10
  4. IBindableFromHttpContext to bind an incoming CloudEvent, instead of controller based Microsoft.AspNetCore.Mvc.Formatters
  5. SystemTextJson instead of NewtonsoftJson
  6. Reduced complexity of the GenerateCloudEvent method by using the native CopyToHttpResponseAsync from CloudNative.CloudEvents.AspNetCore

Successful build @ https://github.com/erwinkramer/sdk-csharp/actions/runs/23054867045

@erwinkramer erwinkramer marked this pull request as ready for review March 13, 2026 13:19
@jskeet
Copy link
Contributor

jskeet commented Mar 13, 2026

Just to set expectations, I'll look at this when I can, but it's unlikely to be for at least a week.

@erwinkramer erwinkramer marked this pull request as draft March 13, 2026 13:32

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="10.0.5" /> <!-- VersionOverride is needed to avoid pulling in a later version of Microsoft.AspNetCore.App that isn't compatible with .NET 10.0. -->
Copy link
Author

@erwinkramer erwinkramer Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could convert the whole repo into .NET 10 in a successive PR, so we don't suffer from tricks like this. I'm not sure how much impact that has yet, so I refrained from making this current change too big.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to support .NET 8 while that's a supported platform. We may be able to target net8 while using the .NET 10 SDK, but I definitely don't want to remote a net8 target.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd like to keep net8 on the IntegrationTests and AspNetCoreSample projects as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, and I don't have the bandwidth to think about it right now. Leave this comment thread open, and I'll reply again when I get round to reviewing the whole PR.

Assert.Contains(cloudEvent.Id, resultContent);
Assert.Contains(cloudEvent.Type, resultContent);
Assert.Contains($"\"{expectedExtensionKey}\": \"{expectedExtensionValue}\"", resultContent);
Assert.Contains($"\"{expectedExtensionKey}\":\"{expectedExtensionValue}\"", resultContent);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we notice here, the Json serializer is handling this slightly different, I think because we're using System.Text.Json now throughout the ASP.NET Core sample. In a successive PR, i could make this a bit more robust.

@erwinkramer erwinkramer marked this pull request as ready for review March 13, 2026 14:32
@erwinkramer
Copy link
Author

Thanks for your quick heads-up @jskeet. I think the PR is ready to go and I'm happy to continue on some other maintenance work related to this repo, in successive PRs.


namespace CloudNative.CloudEvents.AspNetCoreSample
{
// FIXME: This doesn't get called for binary CloudEvents without content, or with a different data content type.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FIXME's are still relevant, I guess. I'd rather put those in separate issues in the GitHub repo so it can be picked up from there.

@erwinkramer erwinkramer force-pushed the main branch 2 times, most recently from 42977d0 to 0b7f66b Compare March 13, 2026 18:33
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants