Fix registration of MVC services #2648
Description
Ideally both of the following configurations should work…i.e a user should be able to call ‘ConfigureMvc’ either before or after AddMvc() and all the options registered would get called in the sequence they were registered.
Currently the issue is that #2 does not work as AddMvc() call doesn’t add options if it was added earlier.
- public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.ConfigureMvc(options =>
{
// This adds both Input and Output formatters based on DataContractSerializer
options.AddXmlDataContractSerializerFormatter();
// To add XmlSerializer based Input and Output formatters.
options.InputFormatters.Add(new XmlSerializerInputFormatter());
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
});
2. public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.ConfigureMvc(options =>
{
// This adds both Input and Output formatters based on DataContractSerializer
options.AddXmlDataContractSerializerFormatter();
// To add XmlSerializer based Input and Output formatters.
options.InputFormatters.Add(new XmlSerializerInputFormatter());
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
});
services.AddMvc();