Skip to content

modernize ASP.NET Core samples#326

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

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

Conversation

@erwinkramer
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, I've thought about it more - I'm fine with this being net10.0 only, and likewise IntegrationTests. I want to keep the production code projects targeting net8.0 for now. We can add a target for net10.0 (in a separate PR) so that we can remove net8.0 when it goes EOL.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The VersionOverride is still in there for now. If I'd have to remove it (and bump the directory package version to 10), I have to modify the GitHub workflow to only run tests on .NET 10, right? Not sure if you want that at this stage.

@erwinkramer erwinkramer marked this pull request as ready for review March 13, 2026 14:32
@erwinkramer
Copy link
Copy Markdown
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.

@erwinkramer erwinkramer force-pushed the main branch 3 times, most recently from 2ca5aaa to 5cccd96 Compare March 13, 2026 18:57
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CloudNative.CloudEvents.AspNetCoreSample.Operations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use a file-scoped namespace for new code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And if this is in a different namespace, please move it to the corresponding folder. (Does it need to be in a different namespace?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed to file-scoped for the samples (including HttpSend sample). For the namespace, I'm not sure if it's worth it to keep a distinct namespace. For simplicity's sake I changed the whole project as CloudNative.CloudEvents.AspNetCoreSample namespace for now, otherwise binding and operations files would each have their own namespace and folder, which is maybe a little too much for those 2 files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sounds fine to me.

global.json Outdated
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.400",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding this comment here, but basically I'd quite like to keep all the "general infrastructure update" changes separate from the sample changes. If I create a PR that makes these changes separately, are you happy to rebase on top of that? (The PR itself will be simple, but I'll need to get it reviewed of course.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure, go for it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I guess that would include the sln to slnx migration from this PR as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup, that was my thinking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See #327 - I'm hoping I can get that reviewed and merged this week.


public ProblemHttpResult Error { get; init; }

public static async ValueTask<CloudEventBinding> BindAsync(HttpContext context, ParameterInfo parameter)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just as a heads-up, I'm really not familiar with IBindableFromHttpContext. I'm mostly following along, but I could easily miss things.


<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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, I've thought about it more - I'm fine with this being net10.0 only, and likewise IntegrationTests. I want to keep the production code projects targeting net8.0 for now. We can add a target for net10.0 (in a separate PR) so that we can remove net8.0 when it goes EOL.

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Mar 31, 2026

Infrastructure PR now merged, so you should be able to rebase onto it.

erwinkramer and others added 16 commits March 31, 2026 19:23
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>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
erwinkramer and others added 6 commits March 31, 2026 19:23
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
- Convert .sln to .slnx
- Update to .NET 10 SDK
- Update unit test targets to net8.0 and net10.0
- Update integration test target to net10.0
- Update sample targets to net10.0
- Update all dependencies as far as they're compatible
- Update protobuf generator and regenerate
- Update actions/setup-dotnet workflow action

Signed-off-by: Jon Skeet <skeet@pobox.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
Signed-off-by: Erwin <erwinkramer@hotmail.com>
This reverts commit f305671.

Signed-off-by: Erwin <erwinkramer@hotmail.com>
@erwinkramer
Copy link
Copy Markdown
Author

@jskeet I guess it's ready to be merged now.

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Mar 31, 2026

I'll have another look when I can - maybe tomorrow evening, but it may be Friday.

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