Asp.net 什么';context.Get()和它的泛型版本之间的区别是什么?
我正在努力熟悉奥文,有很多事情让我困惑。例如,在partial startup.cs class I中,通过Asp.net 什么';context.Get()和它的泛型版本之间的区别是什么?,asp.net,asp.net-identity,owin,katana,Asp.net,Asp.net Identity,Owin,Katana,我正在努力熟悉奥文,有很多事情让我困惑。例如,在partial startup.cs class I中,通过 app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationDbContext.Create
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
有什么区别?为什么我们需要这种通用方法
我可以得到这样的背景:
context.Get<ApplicationDbContext>())
context.GetUserManager<ApplicationUserManager>()
context.Get())
context.GetUserManager()
Get和GetUserManager方法之间有什么区别?为什么我不能为ApplicationUserManager调用context.Get?在
Get
和GetUserManager
这是这两个的源代码
/// <summary>
/// Retrieves an object from the OwinContext using a key based on the AssemblyQualified type name
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="context"></param>
/// <returns></returns>
public static T Get<T>(this IOwinContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
return context.Get<T>(GetKey(typeof (T)));
}
/// <summary>
/// Get the user manager from the context
/// </summary>
/// <typeparam name="TManager"></typeparam>
/// <param name="context"></param>
/// <returns></returns>
public static TManager GetUserManager<TManager>(this IOwinContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
return context.Get<TManager>();
}
//
///使用基于AssemblyQualified类型名称的键从OwinContext检索对象
///
///
///
///
公共静态无法获取(此IOwinContext上下文)
{
if(上下文==null)
{
抛出新的ArgumentNullException(“上下文”);
}
返回context.Get(GetKey(typeof(T));
}
///
///从上下文中获取用户管理器
///
///
///
///
公共静态TManager GetUserManager(此IOwinContext上下文)
{
if(上下文==null)
{
抛出新的ArgumentNullException(“上下文”);
}
返回context.Get();
}
什么是上下文
?dbContext,OWIN context,HttpContext?OWIN context,我认为它显然没有回答问题,Get()和泛型版本之间有什么区别。因此,如果没有区别,我可以轻松调用context.Get()而不是context.GetUserManager?那么为什么我们只需要一个单独的方法来获取UserManager呢?是的。你不需要一个单独的方法,显然你可以交换它们。至于原因,我不确定。可能是早期版本的Identity遗留下来的东西。@Shoe不是Owin的一部分吗?而GetUserManager
是否来自身份?我的意思是它们来自不同的程序集,由不同的组件使用?@trailmaxGet(string)
是OWINGet()
的一部分,GetUserManager()
是标识命名空间中的一些OWIN扩展。