查看 AuthenticationServiceCollectionExtensions.AddAuthentication() 的代码对比 AuthenticationCoreServiceCollectionExtensions.AddAuthenticationCore() ,看起来 AddAuthentication 隐式调用 AddAuthenticationCore,添加一些其他好东西,然后返回 AuthenticationBuilder 的新实例,而不是只返回 IServiceCollection。
我是否正确理解代码?如果是这样,除了编写自己的扩展程序之外,通常是否有任何理由调用 AddAuthenticationCore 而不是 AddAuthentication ?
最佳答案
这似乎是 ASP.NET Core 中的典型模式:Add[xxx]Core
方法添加最低限度以启用功能,但没有任何花里胡哨的东西。它也可能用于使单元测试核心功能更容易。
您可以与 AddMvc
平行对比 AddMvcCore
方法。有一个问题要问Should I use AddMvc or AddMvcCore for ASP.NET Core MVC development? ,要点是它允许对要使用的中间件进行细粒度控制。
回答您的问题:对于典型用户来说,可能没有理由使用 AddAuthenticationCore
.
关于authentication - AddAuthentication 和 AddAuthenticationCore 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60047064/