Search code examples
identityserver4.net-core-3.0asp.net-core-3.0

AddJsonFormatters() missing after migration from .NET Core 2.2 to 3.0


I have a Net Core 2.2 Web Api that I protect with the integration of IdentityServer4. So I started from the tutorial of IDS4 to write the code and there I found the AddJsonFormatters().

I'm triyng to migrate it from .NET Core 2.2 to .NET Core 3.0.

At the moment I have a problem at compile time in the ConfigureServices().

I don't find the AddJsonFormatters() and if I correctly understand, I have to use the AddMvcOptions() to get the same result.

Is this correct? In this case, what is the equivalent configuration?

// .NET Core 2.2
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvcCore()
            .AddAuthorization()
            .AddJsonFormatters();

    // Other code...
}

// .NET Core 3.0
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvcCore()
            .AddAuthorization()
            // Something like this...
            .AddMvcOptions(options =>
            {                       
                //options.OutputFormatters.Add(new SomeKindOf_IOutputFormatter());
                //options.InputFormatters.Add(new SomeKindOf_IInputFormatter(options));
            });

    // Other code...
}

Solution

  • I just found out that IdentityServer4 are slowly updating their samples for .NET Core 3.0. Attached is the link to their newer version of the code for the part you are asking about, hope it helps. https://github.com/IdentityServer/IdentityServer4/blob/master/samples/Quickstarts/1_ClientCredentials/src/Api/Startup.cs