Microsoft AspNet身份Owin CreatePerOwinContext [英] Microsoft AspNet Identity Owin CreatePerOwinContext
问题描述
努力更好地了解OWIN中间件,并通过CreatePerOwinContext提出了一个问题.
公共类MyClass {
public int id {get; set;}
公共静态MyClass Create(){
返回新的MyClass();
}
}
在启动内:
app.CreatePerOwinContext< MyClass>(MyClass.Create);
这实际上是做什么的?从MSDN,我对CreatePerOwinContext的阅读是 注册将被调用以创建类型实例的回调 T 将存储在OwinContext中,该OwinContext可以通过context.Get获取.
因此它创建了一个实例,以后我可以使用context.Get检索该实例.
在我的控制器中,我将检索该实例:
var context = Request.GetOwinContext();
var myclass = context.Get< MyClass>(" MyClass");
我希望能更好地了解如何使用CreatePerOwinContext并弄清楚如何使用context.Get.
谢谢
Kirk deDoes
deDogs
以下链接可能会有帮助
http://www.codeproject.com/Articles /762428/ASP-NET-MVC和身份了解基本知识
http://stackoverflow.com/questions/26626120/扩展方法的目的是什么-createperowincontext-in-owin-impleme
Working to understand the OWIN middleware better, and ha give a question with CreatePerOwinContext.
public class MyClass {
public int id {get;set;}
public static MyClass Create() {
return new MyClass();
}
}
Within Startup:
app.CreatePerOwinContext<MyClass>(MyClass.Create);
What is this actually doing? From MSDN, my reading of CreatePerOwinContext is it will Registers a callback that will be invoked to create an instance of type T that will be stored in the OwinContext which can fetch via context.Get.
So it creates an instance, and later I can retrieve that instance using context.Get.
Within my controller, to retrieve the instance I would:
var context = Request.GetOwinContext();
var myclass = context.Get<MyClass>("MyClass");
I hope for some better insight with how I can use CreatePerOwinContext and clearify how to use context.Get.
Thank you,
Kirk deDoes
deDogs
Following links may help
http://www.codeproject.com/Articles/762428/ASP-NET-MVC-and-Identity-Understanding-the-Basics
http://stackoverflow.com/questions/26626120/what-is-the-purpose-of-the-extension-method-createperowincontext-in-owin-impleme
这篇关于Microsoft AspNet身份Owin CreatePerOwinContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!