1
votes

I want to migrate the AddCsvSerializerFormatters configuration to .NET Core 3.0

Taken from the example code here

services.AddMvc(o =>
    {
        ...
    })
    .AddCsvSerializerFormatters()

A .NET Core 3.0 web api project registers just the controllers, and registering all of Mvc seems overkill.

public void ConfigureServices(IServiceCollection services)
{
  services.AddControllers();
  ...
}

References:

1
Why not services.AddControllers().AddCsvSerializerFormatters();?itminus
Thanks, I never thought of that...🤦‍♂️ Turns out AddControllers implements IMvcBuilder which is the magic glue. Can you add your reply as an answer so I can accept it?Bernard Vander Beken

1 Answers

1
votes

The ServiceCollection.AddControllers() returns an IMvcBuilder type. Since this package adds an extension AddCsvSerializerFormatters() for IMvcBuilder, you can chain the method invocation by:

services.AddControllers().AddCsvSerializerFormatters();

See AddCsvSerializerFormatters():

public static IMvcBuilder AddCsvSerializerFormatters(this IMvcBuilder builder)