AddAuthentication 和 AddAuthenticationCore 有什么区别?

Jer*_*eck 14 authentication asp.net-core

查看AuthenticationServiceCollectionExtensions.AddAuthentication()AuthenticationCoreServiceCollectionExtensions.AddAuthenticationCore()的代码,看起来 AddAuthentication 隐式调用 AddAuthenticationCore,添加一些其他的好东西,然后返回一个新的 AuthenticationBuilder 实例,而不是仅仅返回 IServiceCollection。

我是否正确理解代码?如果是这样,除了编写自己的扩展程序之外,通常是否有任何理由调用 AddAuthenticationCore 而不是 AddAuthentication ?

Mét*_*ule 10

这似乎是 ASP.NET Core 中的典型模式:这些Add[xxx]Core方法添加了最低限度的功能来启用某个功能,但没有任何附加功能。它还可能用于使核心功能的单元测试变得更容易。

AddMvc您可以与vs方法进行比较AddMvcCore。有一个问题问我应该使用 AddMvc 还是 AddMvcCore 进行 ASP.NET Core MVC 开发?,其要点是它允许对您要使用的中间件进行细粒度控制。

回答您的问题:对于典型用户来说,可能没有理由使用 AddAuthenticationCore.

  • 那不是回答问题! (3认同)