Is This Context-Per-Request Implementation Safe?

MerchantAdvance

New Member
Let's say I have a helper class like this:\[code\]public static class RequestHelper { private const String DbContextKey = "DbContext"; public static DbContext CurrentDbContext { get { return HttpContext.Current.Items[DbContextKey] as DbContext; } set { HttpContext.Current.Items[DbContextKey] = value; } }}\[/code\]And then in my \[code\]Global.asax.cs\[/code\] I have:\[code\]protected void Application_BeginRequest() { RequestHelper.CurrentDbContext = new DbContext("some_conn_string_name");}\[/code\]Is this design safe across all requests? Will I run into any problems if I am always doing data access through \[code\]RequestHelper.CurrentDbContext\[/code\]?The reason I ask is that I've seen much more complicated implementations of context-per-request that rely on dependency injection. I feel like I must be missing something obvious, and I'm afraid that I won't notice until I have a large enough number of users in the application.
 
Back
Top