Skip to content

Use scaffolder to generate Web API code #10274

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

Closed
Rick-Anderson opened this issue Jan 8, 2019 — with docs.microsoft.com · 10 comments
Closed

Use scaffolder to generate Web API code #10274

Rick-Anderson opened this issue Jan 8, 2019 — with docs.microsoft.com · 10 comments
Labels
Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link
Contributor

Rick-Anderson commented Jan 8, 2019

Use scaffolder to generate Web API code.

Currently we use a cook book approach and have them copy/paste each method. It might be better to use the scaffold to generate the code, then have a discussion of each generated method. That's what we do in the RP and intro to MVC series.

I propose for the 3.0 version we use the scaffolder. The 2.2 version will keep the copy/paste approach. We can compare CSAT between the two versions.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added the Source - Docs.ms Docs Customer feedback via GitHub Issue label Jan 8, 2019
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Jan 8, 2019
@Rick-Anderson
Copy link
Contributor Author

Rick-Anderson commented Jan 23, 2019

@danroth27 please review. This is marked P2 because it's automaticly done as part of the 3.0 doc updates. cc @tdykstra @scottaddie

Copy link

What would the scaffolding method and is there documentation regarding scaffolding methodology?

@danroth27
Copy link
Member

@glennc are you in favor of updating the basic Web API tutorials to use scaffolding?

@glennc
Copy link
Contributor

glennc commented May 28, 2019

Would you leave both options or switch it over to only show scaffolding? I don't have an objection to showing them scaffolding, especially if what we are showing them to write is no different to what you'd get from the scaffolder.

@Rick-Anderson
Copy link
Contributor Author

Currently we have

  • Add Get methods - copy/paste the following code
  • Add a Create method copy/paste the following code
  • Add a PutTodoItem method copy/paste the following code
  • Add a DeleteTodoItem method copy/paste the following code

That would be changed to

  • Run the scaffolder
  • Examine the generated Get methods - we'd go into more detail on the generated code. Test the Get methods
  • Examine the xyz method - explain it, test it, etc.

I could add a note saying you don't need to run the scaffolder, just copy/paste the methods you're interested in.

The code we're using now is the same as the scaffolder generates.

Copy link

While running through the tutorial using VS 2019, .Net Core 2.2, and generating the code with API Controller with actions, using Entity Framework, I noticed the generated code does not match the code in the tutorial. Specifically,

Post Method
Generated code: return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
Tutorial code: return CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item);

Delete Method
Generated code: return todoItem;
Tutorial code: return NoContent();

Put Method
Generated code:

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!TodoItemExists(id))
{
return NotFound();
}
else
{
throw;
}
}

Tutorial code: await _context.SaveChangesAsync();

Generated code has the TodoItemExists method, but the tutorial does not.

private bool TodoItemExists(long id)
{
return _context.TodoItems.Any(e => e.Id == id);
}

@Rick-Anderson
Copy link
Contributor Author

To do:

Delete Method
Generated code: return todoItem;
Tutorial code: return NoContent();

Verify with the scaffolding folks.

@cremor
Copy link

cremor commented Jun 22, 2019

Delete Method
Generated code: return todoItem;
Tutorial code: return NoContent();

Verify with the scaffolding folks.

Related:
dotnet/Scaffolding#983
dotnet/aspnetcore#8855

Copy link

and services.AddControllers(); for new version

@Rick-Anderson
Copy link
Contributor Author

This was complete last version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

8 participants