Tutorial :Passing enviroment variables to Data Access Layer



Question:

Every stored procedure we write has to have clientip, serverip, windows username, etc passed on to it.

The question is how do I efficiently pass these to DAL?


Solution:1

I'm assuming this is a web app in ASP.NET. If that's the case, you have access to all these things in the context of a web request outside of the web application through the following static instance:

System.Web.HttpContext.Current  

If everything you need is standard stuff that you usually have in the Request, Response, and User objects that are available by default at the Page level, then this should be all you need. If you need information that is custom to your web app, then Ben's answer (above) should work.


Solution:2

You should have all of the above data accessible either in the System.Environment class, or in your own Thread Principal of some kind. Your DAL can easily pull in from both or either of those sources.


Solution:3

Create a class to hold this data, a factory to build it and helper methods to consume it.

IUserContext  {  int param1 {get;set;}  int param2 {get;set;}    SqlParameter[] GetSqlParameters();  }    UserContext : IUserContext{}    UserContextFactory  {      internal IUserContext IUserContextFromRequest(){}  }  

Good luck


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »