![]() Further, the context is request-scoped, so it too is instantiated and destroyed with each request. Controller's are instantiated and destroyed with each request, regardless of whether it's the same or a different user making the request. So what could be going wrong here, any suggestions why ASP.NET Core's EF calls within Userstore are not using the local DBSet of entities? Or am I thinking this wrongly - and each time a call is made to a controller, a new EF context is created? The EF performance paper says: It’s important to note that two different ObjectContext instances will have two different ObjectStateManager instances, meaning that they have separate object caches. In the Identity code, it seems that this method calls the UserStore FindByIdAsync method that calls FindAsync on the DBSet of users. Services.AddIdentity().AddDefaultTokenProviders().AddEntityFrameworkStores() Īnd read the user in each controller method: var user = await _userManager.GetUserAsync(HttpContext.User) I set up the default EF and Identity stores in startup.cs's ConfigureServices: services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("MyDBContext"))) I know there's so many ways to set Identity up, and its changed over the versions that maybe I'm not doing something right, or is there a fundamental problem here that could be addressed. ![]() I noticed that the asp.net core Identity code uses a DBSet to hold the entities and that subsequent calls to it should be reading from the local entities in memory and not hitting the DB, but it appears that every time, my code requires a DB read (I know as I'm running SQL Profiler and see the select queries against AspNetUsers being run using Id as the key) ![]() I'm working with a standard ASP.NET Core 2.1 program, and I've been considering the problem that a great many of my controller methods require the current logged on user to be retrieved. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |