【发布时间】:2020-02-19 20:44:50
【问题描述】:
我有一个 Net Core 2.2 Web Api,我通过集成 IdentityServer4 来保护它。所以我从 IDS4 的教程开始编写代码,在那里我找到了 AddJsonFormatters()。
我正在尝试将其从 .NET Core 2.2 迁移到 .NET Core 3.0。
目前我在 ConfigureServices() 的编译时遇到问题。
我没有找到 AddJsonFormatters(),如果我理解正确,我必须使用 AddMvcOptions() 来获得相同的结果。
这是正确的吗?这种情况下,等效的配置是什么?
// .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...
}
【问题讨论】:
-
在 3.0 中,
AddMvcCore会自动注册SystemTextJsonInputFormatter和SystemTextJsonOutputFormatter,因此您不需要为此调用。现在首选的方法似乎是使用AddControllers等,但仍然支持AddMvcCore。 -
@KirkLarkin 我删除了旧的 2.2 代码,只使用了 AddControllers(),现在它可以工作了。
标签: identityserver4 .net-core-3.0 asp.net-core-3.0