I have a problem with DBContext
while creating httpmodule that uses Entity Framework
.
I'd like to inject DBContext
into the httpmodule
like injecting dependency in constructor
.
Is there any solution for me?
in MyHTTPModule
public class MyHTTPModule: IHttpModule { ... public void OnBeginRequest(object sender, EventArgs e) { HttpApplication Application = (HttpApplication)sender; HttpContext Context = Application.Context; string filepath= Context.Request.FilePath; MyDBContext db = new MyDBContext(); var file = db.file.FirstOrDefault(r => r.filename == filepath); ... } }
What I want is injecting dbcontext into httpmodule like:
public class MyHTTPModule: IHttpModule { private MyDBContext db; public MyHTTPModule(MyDBContext dbcontext) { db = dbcontext; } ... public void OnBeginRequest(object sender, EventArgs e) { HttpApplication Application = (HttpApplication)sender; HttpContext Context = Application.Context; string filepath= Context.Request.FilePath; var file = db.file.FirstOrDefault(r => r.filename == filepath); ... } }