Accessing the HttpContext from a DbContext

added by DotNetKicks
4/14/2020 2:33:18 PM

311 Views

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.


0 comments