AspNetCore3.1_Secutiry源码解析_2_Authentication_核心对象
holdengong 人气:1
# 系列文章目录
- [AspNetCore3.1_Secutiry源码解析_1_目录](https://holdengong.com/aspnetcore3.1_secutiry源码解析_1_目录)
- [AspNetCore3.1_Secutiry源码解析_2_Authentication_核心项目](aspnetcore3.1_secutiry源码解析_2_authentication_核心项目)
- AspNetCore3.1_Secutiry源码解析_3_Authentication_Cookies
- AspNetCore3.1_Secutiry源码解析_4_Authentication_JwtBear
- AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth
- AspNetCore3.1_Secutiry源码解析_6_Authentication_OpenIdConnect
- AspNetCore3.1_Secutiry源码解析_7_Authentication_其他
- AspNetCore3.1_Secutiry源码解析_8_Authorization_核心项目
- AspNetCore3.1_Secutiry源码解析_9_Authorization_Policy
# 依赖注入
框架提供了三个依赖注入重载方法。
```csharp
//注入认证服务
services.AddAuthentication();
//注入认证服务并制定默认架构名
services.AddAuthentication("Cookies");
//注入认证服务并设置配置项
services.AddAuthentication(config =>
{
});
```
看看注入代码
```csharp
public static AuthenticationBuilder AddAuthentication(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddAuthenticationCore();
services.AddDataProtection();
services.AddWebEncoders();
services.TryAddSingleton
加载全部内容