Public Shared Property in a DLL

  • Thread starter Michael G. Schneider
  • Start date
M

Michael G. Schneider

Suppose there is a ASP dot.net web application and a dot.net class library
(written with vb dot.net). The web application references the class library.
The class library contains a ...

Public Class test
Public Shared Property() As String
...
End Property
End Class

Of course, the web application is used by many user in parallel. Now, will
the above property exists once for each user, or will it exist only once for
all users?

Michael G. Schneider
 
M

Michael G. Schneider

Aidy said:
All users will see the same property value.

Thanks a lot for the very fast response.

Is it possible to have a "global variable" in the DLL, which exists
per-user?

Michael G. Schneider
 
M

Michael G. Schneider

Aidy said:
If you want something per-user then use the Session object.

Thanks a lot for the answer.

With Session you suggest the HttpSessionState object. Correct? How can I use
that object in the DLL? And is it ok to use it inside the DLL? Maybe the DLL
is not used from within an ASP application. Maybe it is used from within an
EXE.

What I want to have, is the following. There is a DLL. It will be used from
within an ASP dot.net application, and also from an EXE program. The DLL
needs some global data (for example some configuration data that is read
from an XML file on startup). I want this global data to be read once, then
used several times as long as the DLL is active. In case of the web
application, the global data may not be shared among the users.

Michael G. Schneider
 
M

Michael G. Schneider

Eliyahu Goldin said:
A session variable is your closest match.

Also many thanks for your answer. There is a longer response in the other
part of this thread.

Michael G. Schneider
 
P

Patrice

You could desing ariound thios. For example in a stand alone app you have
only a single user. In aweb app you'll need to know whih user is calling
your app so that you can get the correspoing confi (bascially it could be a
collection).

Hard to tell but another way is to avoid this. What is this DLL supposed to
do. It could just do what you need to and have paramters provided by the
external world allowing to sotre them as you which rather than having the
DLL directly accessing those pamreatmers..

Hard to say more as we don"t know what it is about...

Good luck
 
M

Michael G. Schneider

Hard to say more as we don"t know what it is about...

Thanks a lot for the answer. I can give you some more information. Maybe the
task is clearer then.

The DLL offers some classes. Each of these classes offers several methods.
Each of these methods needs basic data. Maybe it is data that is read from a
database or from a configuration XML file.

I do not want to read the basic data on each an every method call. The DLL
should read the data once and store it internally.

This might be solved by an extra method, which reads the basic data, stores
it in some objects, and returns it to the caller. The caller would then hand
over this data to each of the method calls. Something like

Dim oBaseData As DLL.BaseData
Dim oWorker As DLL.Worker
oWorker = New DLL.Worker
oBaseData = oWorker.ReadBaseData("server", "database")
oWorker.Calc1(oBaseData, ...)
oWorker.Calc2(oBaseData, ...)
oWorker.Calc3(oBaseData, ...)

So the oBaseData would be passed into the DLL, and then also from one
function to the next function within the DLL.

This is not so nice. Many parameters have to be passed along.

As this is really "global data", I prefered to have a "global variable" and
access that it from each DLL function.

Michael G. Schneider
 
W

Walter Wang [MSFT]

Hi Michael,

Based on my understanding, you need to make your class library used by both
your web application and windows application and you need to make sure some
classes could use per-user settings/data.

I think you could add reference to System.Web to your class library and use
HttpContext.Current to determine if it's used by a web application or
windows application. If it's web application (having a non-null
HttpContext.Current), then use the session; otherwise, use a global object
such as Hashtable.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Michael G. Schneider

I think you could add reference to System.Web to your class library and
use
HttpContext.Current to determine if it's used by a web application or
windows application. If it's web application (having a non-null
HttpContext.Current), then use the session; otherwise, use a global object
such as Hashtable.

Hello Walter,

thanks a lot for the answer. This does work.

I thought that in a non-web application I was not allowed to reference the
web parts of dot.net. However, it does work. So you can code references to
objects such as HttpContext.Current - you only have to take care of the fact
that these references might be Nothing.

Michael G. Schneider
 
P

Patrice

Another option would be to insulate the DLL form the underlying settings
storage using a "provider" scheme.
 
W

Walter Wang [MSFT]

Hi Michael,

Adding reference to System.Web in your class library should be ok. Also,
the System.web assembly is included in default .NET Framework
redistribution therefore you don't need to worry if your class library is
used by a windows application.

Following KB also demonstrates such usage when you need to output trace
message to a web application from a class library.

#HOW TO: Get Trace.Write Statements in Regular Code to Appear in Page Logs
by Using Visual C# .NET
http://support.microsoft.com/kb/327848


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top