关于[Development With A Dot - Accessing the HttpContext from a DbContext]的摘要:
Sometimes it might be necessary to access the current HttpContext from inside a DbContext, namely, from inside the OnConfiguring or OnModelCreating methods. Why? Well, for once, because of multitenancy: we may want to be able to decide the connection string to use based on the requesting or the host's domain, the current user or some other request parameter. Here the internal dependency injection (Instance) can’t help, because it cannot be used inside these methods.
原文地址: https://weblogs.asp.net/ricardoperes/accessing-the-httpcontext-from-a-dbcontext