从 2.2 升级到 Dotnet Core 3.1,EF 核心不断抱怨EF1001:通过在我的项目中放置感叹号来使用内部 ef 核心 api。
但是在编译过程中没有显示错误/警告。我不知道哪一行代码导致了问题。
我可以知道如何找出我不应该使用的 API/方法吗?
我有一个 ASP.NET Core 3.0 应用程序。在 Startup 类中,在方法中
public void ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)
我想配置身份验证,以便 JWT 由我的 ISecurityTokenValidator 实现处理:CustomJwtSecurityTokenHandler。为此,我需要获取实现类的实例 CustomJwtSecurityTokenHandler,其构造函数需要注入一些服务。出于这个原因,我需要打电话:
var serviceProvider = services.BuildServiceProvider();
Run Code Online (Sandbox Code Playgroud)
为了创建一个“临时” serviceProvider 来获取我的带有注入参数的 CustomJwtSecurityTokenHandler 实例。
我最终得到了这个代码(效果很好!):
services.AddAuthentication(authenticationOptions =>
{
authenticationOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
authenticationOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(jwtBearerOptions =>
{
jwtBearerOptions.SecurityTokenValidators.Clear();
CustomJwtSecurityTokenHandler customJwtSecurityTokenHandler;
{
// create a temporary serviceProvider, in order to retrieve a CustomJwtSecurityTokenHandler (supposed to be registered as addin!).
var serviceProvider = services.BuildServiceProvider();
customJwtSecurityTokenHandler = serviceProvider.GetService<CustomJwtSecurityTokenHandler>();
}
//below line adds the custom validator class
jwtBearerOptions.SecurityTokenValidators.Add(customJwtSecurityTokenHandler);
});
Run Code Online (Sandbox Code Playgroud)
只是,从方法 ConfigureServices 中调用 …