Using 2.0.0-preview2-final mvc nuget version.
MvcOptions.InputFormatters is empty when use AddMvcCore and action method with [FromBody] attribute. Throws "'Microsoft.AspNetCore.Mvc.MvcOptions.InputFormatters' must not be empty. At least one 'Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter' is required to bind from the body."
Works with AddMvc().
Is it expected JsonInputFormatter is not added with AddMvcCore by default? Do we have some extension method to configure formatters same way AddMvc does?
You'd have to call AddJsonFormatters() to setup Json formatters. It's what AddMvc does - https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs#L52
AddMvc and AddMvcCore, and which one should I use when using ASP.NET MVC Core?AddMvcCore is the answer to the previous question, is it essential it should be added after AddMvcCore or order doesn't matter?What is the difference between AddMvc and AddMvcCore, and which one should I use when using ASP.NET MVC Core?
checkout the answer on stackoverflow regarding the difference about this two - https://stackoverflow.com/a/40097363/5441673
which one you should use - it depends on what you need. In my case I use AddMvcCore as I don't want some middlewares to be applied with AddMvc call (like Razor, I don't need serverside rendering in my app).
If AddMvcCore is the answer to the previous question, is it essential it should be added after AddMvcCore or order doesn't matter?
Either AddMvc or AddMvcCore should be used. AddMvc under the hood calls AddMvcCore and then adds some additional services. See source code for AddMvc here - https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs
AddMvc should be used by most people, AddMvcCore has nothing, it's barebones and you have to add all of the features back by hand. It's really more of a building block than anything else. You should really understand what you're doing if you plan to use it.
So if I'm only using web API (no UI), should I go for Core?
Why does it matter? What costs are you trying to avoid?
If it adds unnecessary services I thought perhaps use the minimal Core call.
How does that affect your application?
OK nevermind.
I found the source-code so it's pretty much self-explanatory.
Looking up the source code, I decided to use AddMvcCore, since I don't need Views, Razor etc..
Thanks for your help!
Just to make sure you understand what you're getting into. You really do have to add everything back (which is fine if you know what you are doing). As you write more code and more features don't work, look at AddMvc and start adding things back (validation, formatters, authentication)
Thanks for your dedication David!
Most helpful comment
Just to make sure you understand what you're getting into. You really do have to add everything back (which is fine if you know what you are doing). As you write more code and more features don't work, look at AddMvc and start adding things back (validation, formatters, authentication)