Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ASP.NET Core sample to use minimal host #283

Merged

Conversation

captainsafia
Copy link
Contributor

@captainsafia captainsafia commented Mar 5, 2024

This updates the ASP.NET Core sample to use some of the "modern" functionality available in .NET 6+ including top-level statements, the new minimal-style WebApplicationBuilder, and removal of the Startup class.

I've also included an .http file to support testing of the endpoint.

As a next step, I'd like to take a stab at replacing the controller class + input formatter with a minimal endpoint + BindAsync implementation, but I think this change is helpful for now.

CE-SpecVersion: 1.0
CE-Type: "com.example.myevent"
CE-Source: "urn:example-com:mysource:abc"
CE-Id: "c457b7c5-c038-4be9-98b9-938cb64a4fbf"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In an ideal world, I wouldn't hardcode the GUID here and would instead use dynamic variable support provided by .http files. However, it appears that each editor recognizes a different dynamic variable for generating a GUID.

VS Code and VS respect {{$guid}} and Rider respects {{$random.uuid}} so there is no universal value to include here. Opted to hard code for now.

@captainsafia captainsafia force-pushed the safia/update-aspnetcore-sample branch from 63ed6b5 to ae5b5a9 Compare March 5, 2024 22:08
Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

I'm definitely happy to use the more modern style of app startup.

Does anything use the new .http file? (It's not something I've come across before, and I'm not sure whether it's used implicitly or whether it's just as an example that has some IDE support for "send this request".) It might be worth a README file in this directory.

namespace CloudNative.CloudEvents.AspNetCoreSample
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers(opts =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an expression-bodied lambda here?

(I've always found it unusual that so many MS docs use a block-bodied lambda for ASP.NET Core option actions, even when there's only a single statement. Admittedly that makes it easier to add more statements, but...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use an expression-bodied lambda here?

Sure! I don't mind using something terser here.

@captainsafia
Copy link
Contributor Author

Does anything use the new .http file? (It's not something I've come across before, and I'm not sure whether it's used implicitly or whether it's just as an example that has some IDE support for "send this request".) It might be worth a README file in this directory.

Rider and VS provide built-in support for executing the requests in the .http file. VS Code has an extension that you can use. I'll pop a README in the sample directory that outlines how to run the sample and execute commands against it with the CLI tool and HTTP files.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

Thanks so much, the readme in particular is great!

@@ -0,0 +1,44 @@
# Samples
Copy link
Contributor

Choose a reason for hiding this comment

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

This is amazing!

@jskeet
Copy link
Contributor

jskeet commented Mar 6, 2024

Doh - one thing, we need each commit to have a "Signed-off-by" line.

If you could squash the two commits down to one that contains the Signed-off-by, I'll then merge. Thanks!

Signed-off-by: Safia Abdalla <safia@safia.rocks>
Signed-off-by: Safia Abdalla <safia@safia.rocks>
@captainsafia captainsafia force-pushed the safia/update-aspnetcore-sample branch from fc32041 to 2863974 Compare March 6, 2024 17:41
@captainsafia
Copy link
Contributor Author

If you could squash the two commits down to one that contains the Signed-off-by, I'll then merge. Thanks!

Woop -- I ended up signing the second commit and force-pushing. If you'd prefer I squash let me know.

@jskeet
Copy link
Contributor

jskeet commented Mar 6, 2024

If you could squash the two commits down to one that contains the Signed-off-by, I'll then merge. Thanks!

Woop -- I ended up signing the second commit and force-pushing. If you'd prefer I squash let me know.

Fingers crossed it'll be fine - I'll squash it myself as part of merging, which I think should work...

@captainsafia
Copy link
Contributor Author

Build failure! Embarrassing 🙊 I'll fix this

Signed-off-by: Safia Abdalla <safia@safia.rocks>
@jskeet jskeet merged commit 3b78a26 into cloudevents:main Mar 6, 2024
2 checks passed
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