Fred2020
Fred2020

Reputation: 495

.NET Framework to .Net Core skillset transfer

When setting up a .NET Core Web Application, there are two choices available:

API: A project template for creating an ASP.NET Core application with an example Controller for a RESTful HTTP service. This template can also be used for ASP.NET Core MVC Views and Controllers

Web Application (Model-View-Controller): A project template for creating an ASP.NET Core application with example ASP.NET MVC Views and Controllers. This template can also be used for RESTful HTTP services

Are these projects identical when created or are there differences?

If no differences then why the separation? ... just different scaffolding classes created?

Upvotes: 1

Views: 131

Answers (3)

Guillaume S.
Guillaume S.

Reputation: 1545

  • In .NET Framework, the Web API framework was totally separate from the MVC framework. One project can not do both.

  • In .NET Core, there is no distinction(*) They both use the MVC middleware. One project can do both.

I suppose they have kept two project templates in Visual Studio because .NET coders are used to it. But it will just change some lines of code in Startup.cs. You'll never get stuck because of your initial choice.

(*) The only difference are indeed the conventional ways of coding one or the other. For instance in a "traditional" app, the controllers returns views with HTML and the route are all defined in Startup.cs. In a "API" app the controllers will return views in JSON by default (or XML), and the routes are attribute based.

Upvotes: 1

As of ASP.NET Core 3.0, they are indeed different and they will also generate different scaffolding. The reason for this is that 3.0 allows far more granular control over what features are enabled for your controllers. One of the most important changes is that Razor view support can be enabled or disabled - in previous versions, views could always be rendered from a controller, but for API controllers which don't ever return views, this is unnecessary and adds overhead. 3.0 allows you to choose whether you want Razor support in your controllers or not - the "Web Application (Model-View-Controller)" template uses the former via AddControllersWithViews, the "API" template the latter with AddControllers.

A more detailed overview of the differences: https://andrewlock.net/comparing-startup-between-the-asp-net-core-3-templates/

Upvotes: 0

Seyedraouf Modarresi
Seyedraouf Modarresi

Reputation: 1297

Maybe some time you want to just create APIs for exposing a service to the service consumer, on the other hand, you may want to create a web application based on MVC, in this situation you have created a backend for both your application and the services you want to expose.

Upvotes: 0

Related Questions