Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Property Class "Userinfo" like "Firstname,Connectionstring etc" that holds Information upon login. Now, I've Create a Class "Report" that accept UserInfo class upon Instantiating Report Class.

How Can I solve this Dependency Injection thing ?

1 solution

The question makes no sense. "Dependency injection" is not a problem to be solved, it is a technique used to solve other problems, a widely-known design pattern. Please see:[^].

Now, if you explain your problem instead of what is written in your post, the actual problem about "UserInfo", "Report", etc., you classes which you never described, we will gladly try to help you, but no one is going to guarantee you that it will be resolved using dependenfcy injection. When you need to ask a question on some problem, you should not specify the method of solving this problem at the same time, it would be incorrect.


The problems of "global" objects (it would be more correctly to discuss object sharing instead, some weaker concept) in ASP.NET is reduced to the fundamental facts: HTTP protocol is stateless, and all the lifetime of the application (code behind) lies in single HTTP request/response. Not only the global memory objects cannot be shared between different pages, they are not shared between postbacks. Please see:[^],[^].

This imposes draconian limitation on the Web programming, and the approaches to implementation of states include the following:[^].

Generally, you need to store the state somewhere. In practice, if we are discussing user information, some database is most usually used. The databases already provide transactional mechanisms which will allow you not to worry about synchronization of request from different users. Using something else (for example, some files on the server side) would be utterly impractical but possible in principle…

Share this answer
Comments 28-Oct-13 6:39am    
Hmm ok any I solve it my self by Using Global variables I can Access the data of my UserInfo to any other Class in my ASP.NET when Ever I instantiate new UserInfo..
Sergey Alexandrovich Kryukov 28-Oct-13 15:19pm    
Okay, it brings us to another step: there is no such thing as "global variable" in .NET. Not at all. And this is great: first, "global variables" are never really needed, secondly, they are potentially dangerous.
—SA 3-Nov-13 23:16pm    
You said the there is no such thing as "Global variable" in .NET, I was referring to this link
"" that's what I've understand.

Anyway,so how can I resolve this issue without the global variable?
Sergey Alexandrovich Kryukov 4-Nov-13 0:09am    
I cannot get responsibility for this not very literate article, which uses not commonly used terminology and looks like the author has no idea of another well-known pattern pattern, singleton. After all, this is just terminology, but is someone decides to call type member a "variable" and static member a "global variable" (both incorrect), this person should at least define the terms. And the claim "global variables are useful in ASP.NET" remains unproven, even if it means "static members".
Sergey Alexandrovich Kryukov 4-Nov-13 0:20am    
Please see my update to the answer, after [EDIT].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900