0

I want to develop an application with React and ASP.Net Core. The default template comes with MVC architecture. What's the point of MVC when using React with ASP.NET Core? Isn't WebAPI as backend and React as frontend a better approach?

Thank you!

5
  • No you don't need MVC. Creating a new ASP.NET core Web API project does not adds any other dependencies than Microsoft.NETCore.App Commented Apr 8, 2018 at 18:40
  • Thank you for your comment Aseem. Then, why the default project adds it? What's the best practice? Commented Apr 8, 2018 at 18:47
  • 1
    MVC and Web API got combined in Core. You can build either MVC controllers or API controllers with MVC Core. Commented Apr 8, 2018 at 18:50
  • @SherleyDev I am using VS on OSX. MVC is not added when I create a new Web API project. Perhaps this happens on windows. Commented Apr 8, 2018 at 19:02
  • It is added when using react template. (dotnet new react) Commented Apr 8, 2018 at 19:25

1 Answer 1

1

As @juunas commented, it's all MVC. More accurately, it's all "Core", but the extensions methods used to bootstrap the framework all use "MVC" in their name. If you don't need view rendering and such, it's possible you can get by with doing services.AddMvcCore(), instead of services.AddMvc(). That will reduce the service load slightly, but also may not include everything you might want to use.

If you refer to the source, you can see that services.AddMvc() first calls AddMvcCore and then continues to also add:

builder.AddApiExplorer();
builder.AddAuthorization();

AddDefaultFrameworkParts(builder.PartManager);

// Order added affects options setup order

// Default framework order
builder.AddFormatterMappings();
builder.AddViews();
builder.AddRazorViewEngine();
builder.AddRazorPages();
builder.AddCacheTagHelper();

// +1 order
builder.AddDataAnnotations(); // +1 order

// +10 order
builder.AddJsonFormatters();

builder.AddCors();

If you don't need any of that, you can just go with AddMvcCore and call it a day. If you do need certain bits, you can always add those manually, i.e.:

services.AddMvcCore();
services.AddJsonFormatters();
services.AddCors();
// etc.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.