If I wish to inject my DbContext
into one of my controllers as follows:
public class HomeController : Controller
{
MyDbContext _db;
public HomeController(MyDbContext db)
{
_db = db;
}
...
}
What is the correct way to configure this with Unity
. The context would have to intantiated per request so PerRequestLifetimeManager
seems like the natural choice. But from reading this documentation it seems that PerRequestLifetimeManager
is advised against. The terms "thread-unsafe dependencies" make me nervous about using it as do the warning about it causing "bugs in the end user’s application code". The warnings seem to be very vague though so that it is not clear what the dangers actually are. Can anyone give examples of the kind of bugs that can occur from the use of PerRequestLifetimeManager
? And if this lifetime manager is advised against, what would be a better way to inject the DbContext
into my controllers?