473,804 Members | 4,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instantiate an object in two ways???

J-T
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials = System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is not
good because everytime you call doSomthing(..) a new instance is created.I
do agree with it ,but the first approach in an aasp.net application has the
same demrits ,unless you put the object inside application variable or
session variable and persist it.Other wise when you are done working with
the object it is ready for the garbage collector to be collected and when
the second request arrives ,if the object is collected then you need to
create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks
Nov 19 '05 #1
7 1997
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

However, you are opening yourself up for potential threading issues. If 2
people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time? Depending on
what your object does, you may need to synchronize access to it. Which could
potentially slow down your app if it takes a long time to complete its work,
as well as adding complexity to anything using it, because now it has to
worry about making sure it is safe to access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation of
this object is not expensive, and it will be garbage collected when the
request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials = System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is
not good because everytime you call doSomthing(..) a new instance is
created.I do agree with it ,but the first approach in an aasp.net
application has the same demrits ,unless you put the object inside
application variable or session variable and persist it.Other wise when
you are done working with the object it is ready for the garbage collector
to be collected and when the second request arrives ,if the object is
collected then you need to create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks

Nov 19 '05 #2
J-T
> The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected. Why it is not gargage collected? Imagine a request makes this object be
created and when the request is done the object is there ,may hang around
for a while and if no one else (no other request) uses that one ,then it has
no reference to it and it's ready to be garbage collected.right ?

However, you are opening yourself up for potential threading issues. If 2
people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time?
ASP.NET application is a multi-threaded one and there is always multiple
threads working with objects it create,There is no way of getting rid of
multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl... The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

However, you are opening yourself up for potential threading issues. If 2
people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time? Depending on
what your object does, you may need to synchronize access to it. Which
could potentially slow down your app if it takes a long time to complete
its work, as well as adding complexity to anything using it, because now
it has to worry about making sure it is safe to access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation of
this object is not expensive, and it will be garbage collected when the
request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials = System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is
not good because everytime you call doSomthing(..) a new instance is
created.I do agree with it ,but the first approach in an aasp.net
application has the same demrits ,unless you put the object inside
application variable or session variable and persist it.Other wise when
you are done working with the object it is ready for the garbage
collector to be collected and when the second request arrives ,if the
object is collected then you need to create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks


Nov 19 '05 #3
1. No, it is not right. When it is a static object, it means it belongs to
class type. And there is only one of that. Once it is instantiated, it stays
around for the lifetime of the application. Meaning until asp.net is shut
down or recycled.

2. ASP.NET is multithreaded - and if it wasn't, you would have a very very
slow application. This is why I suggested having the static object is not a
way to go - you have to start worrying about multiple threads accessing your
object at the same time.

"J-T" <J-*@microsft.com> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

Why it is not gargage collected? Imagine a request makes this object be
created and when the request is done the object is there ,may hang around
for a while and if no one else (no other request) uses that one ,then it
has no reference to it and it's ready to be garbage collected.right ?

However, you are opening yourself up for potential threading issues. If 2
people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time?


ASP.NET application is a multi-threaded one and there is always multiple
threads working with objects it create,There is no way of getting rid of
multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

However, you are opening yourself up for potential threading issues. If 2
people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time? Depending on
what your object does, you may need to synchronize access to it. Which
could potentially slow down your app if it takes a long time to complete
its work, as well as adding complexity to anything using it, because now
it has to worry about making sure it is safe to access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation of
this object is not expensive, and it will be garbage collected when the
request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials = System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is
not good because everytime you call doSomthing(..) a new instance is
created.I do agree with it ,but the first approach in an aasp.net
application has the same demrits ,unless you put the object inside
application variable or session variable and persist it.Other wise when
you are done working with the object it is ready for the garbage
collector to be collected and when the second request arrives ,if the
object is collected then you need to create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks



Nov 19 '05 #4
J-T
About the first method,

As you can see ,it is using an static variable ,and I think static variables
are stored in the heap and objects stored on the heap can be accessed by all
threads.My object is a readonly object.what I mean by read only is that none
of the threads are trying to change it ,they only want to use it,so none of
those threads lock the object.Having said all this,do you still think that I
have still thread issue.

Thanks
"Marina" <so*****@nospam .com> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
1. No, it is not right. When it is a static object, it means it belongs
to class type. And there is only one of that. Once it is instantiated, it
stays around for the lifetime of the application. Meaning until asp.net is
shut down or recycled.

2. ASP.NET is multithreaded - and if it wasn't, you would have a very very
slow application. This is why I suggested having the static object is not
a way to go - you have to start worrying about multiple threads accessing
your object at the same time.

"J-T" <J-*@microsft.com> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

Why it is not gargage collected? Imagine a request makes this object be
created and when the request is done the object is there ,may hang around
for a while and if no one else (no other request) uses that one ,then it
has no reference to it and it's ready to be garbage collected.right ?

However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time?


ASP.NET application is a multi-threaded one and there is always multiple
threads working with objects it create,There is no way of getting rid of
multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time? Depending on
what your object does, you may need to synchronize access to it. Which
could potentially slow down your app if it takes a long time to complete
its work, as well as adding complexity to anything using it, because now
it has to worry about making sure it is safe to access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation
of this object is not expensive, and it will be garbage collected when
the request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other
problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials =
System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is
not good because everytime you call doSomthing(..) a new instance is
created.I do agree with it ,but the first approach in an aasp.net
application has the same demrits ,unless you put the object inside
application variable or session variable and persist it.Other wise when
you are done working with the object it is ready for the garbage
collector to be collected and when the second request arrives ,if the
object is collected then you need to create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks



Nov 19 '05 #5
J-T
If your answer to my previous post is NO,can you guid me to some references
I can read more about that specific behavior?

Thanks a lot for follwoing up this.
"Marina" <so*****@nospam .com> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
1. No, it is not right. When it is a static object, it means it belongs
to class type. And there is only one of that. Once it is instantiated, it
stays around for the lifetime of the application. Meaning until asp.net is
shut down or recycled.

2. ASP.NET is multithreaded - and if it wasn't, you would have a very very
slow application. This is why I suggested having the static object is not
a way to go - you have to start worrying about multiple threads accessing
your object at the same time.

"J-T" <J-*@microsft.com> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

Why it is not gargage collected? Imagine a request makes this object be
created and when the request is done the object is there ,may hang around
for a while and if no one else (no other request) uses that one ,then it
has no reference to it and it's ready to be garbage collected.right ?

However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time?


ASP.NET application is a multi-threaded one and there is always multiple
threads working with objects it create,There is no way of getting rid of
multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
The first way, you will have one instance for the entire asp.net app. It
will not be garbage collected.

However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads are
accessing this one instance of the object at the same time? Depending on
what your object does, you may need to synchronize access to it. Which
could potentially slow down your app if it takes a long time to complete
its work, as well as adding complexity to anything using it, because now
it has to worry about making sure it is safe to access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation
of this object is not expensive, and it will be garbage collected when
the request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other
problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I can instantiate my object in my *ASP.NET* application in two ways:

A)
public sealed class RSSingleton
{

private static ReportingServic eProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServic eProxy();
m_RsProxy.Crede ntials =
System.Net.Cred entialCache.Def aultCredentials ;
m_RsProxy.Url =
ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
"/ReportService.a smx";
}
internal static ReportingServic eProxy Instance{get{re turn m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{

}
public static ReportingServic eProxy Proxy
{
get
{
ReportingServic eProxy rsProxy = new ReportingServic eProxy();
rsProxy.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
return rsProxy;
}
}
public static string doSomthing(..)
{
Proxy.Render(.. .)
}
}
I personally like the second one.Some people say that the second one is
not good because everytime you call doSomthing(..) a new instance is
created.I do agree with it ,but the first approach in an aasp.net
application has the same demrits ,unless you put the object inside
application variable or session variable and persist it.Other wise when
you are done working with the object it is ready for the garbage
collector to be collected and when the second request arrives ,if the
object is collected then you need to create another instance.Am I righ?

BTW ReportingServic eProxy is a proxy class of a webservice.

Thanks



Nov 19 '05 #6
If the object will be used for read only purposes, then going the static
route is fine.

"J-T" <J-*@microsft.com> wrote in message
news:OO******** ******@TK2MSFTN GP10.phx.gbl...
About the first method,

As you can see ,it is using an static variable ,and I think static
variables are stored in the heap and objects stored on the heap can be
accessed by all threads.My object is a readonly object.what I mean by read
only is that none of the threads are trying to change it ,they only want
to use it,so none of those threads lock the object.Having said all this,do
you still think that I have still thread issue.

Thanks
"Marina" <so*****@nospam .com> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
1. No, it is not right. When it is a static object, it means it belongs
to class type. And there is only one of that. Once it is instantiated, it
stays around for the lifetime of the application. Meaning until asp.net
is shut down or recycled.

2. ASP.NET is multithreaded - and if it wasn't, you would have a very
very slow application. This is why I suggested having the static object
is not a way to go - you have to start worrying about multiple threads
accessing your object at the same time.

"J-T" <J-*@microsft.com> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
The first way, you will have one instance for the entire asp.net app.
It will not be garbage collected.
Why it is not gargage collected? Imagine a request makes this object be
created and when the request is done the object is there ,may hang
around for a while and if no one else (no other request) uses that one
,then it has no reference to it and it's ready to be garbage
collected.right ?
However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads
are accessing this one instance of the object at the same time?

ASP.NET application is a multi-threaded one and there is always multiple
threads working with objects it create,There is no way of getting rid of
multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
The first way, you will have one instance for the entire asp.net app.
It will not be garbage collected.

However, you are opening yourself up for potential threading issues. If
2 people make a request at the same time, what if both their threads
are accessing this one instance of the object at the same time?
Depending on what your object does, you may need to synchronize access
to it. Which could potentially slow down your app if it takes a long
time to complete its work, as well as adding complexity to anything
using it, because now it has to worry about making sure it is safe to
access this object.

For asp.net, hands down I would go with way #2. Odds are, the creation
of this object is not expensive, and it will be garbage collected when
the request is finished. You aren't really going to see a noticeable
performance difference, and you will avoid a whole lot of other
problems.

"J-T" <J-*@microsft.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
>I can instantiate my object in my *ASP.NET* application in two ways:
>
> A)
> public sealed class RSSingleton
> {
>
> private static ReportingServic eProxy m_RsProxy=null;
> static RSSingleton()
> {
> m_RsProxy = new ReportingServic eProxy();
> m_RsProxy.Crede ntials =
> System.Net.Cred entialCache.Def aultCredentials ;
> m_RsProxy.Url =
> ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
> "/ReportService.a smx";
> }
> internal static ReportingServic eProxy Instance{get{re turn
> m_RsProxy;}}
> }
>
>
> B)
> public class RSFactory
> {
> //Empty constructor
> static RSFactory()
> {
>
> }
> public static ReportingServic eProxy Proxy
> {
> get
> {
> ReportingServic eProxy rsProxy = new ReportingServic eProxy();
> rsProxy.Credent ials =
> System.Net.Cred entialCache.Def aultCredentials ;
> return rsProxy;
> }
> }
> public static string doSomthing(..)
> {
> Proxy.Render(.. .)
> }
> }
>
>
> I personally like the second one.Some people say that the second one
> is not good because everytime you call doSomthing(..) a new instance
> is created.I do agree with it ,but the first approach in an aasp.net
> application has the same demrits ,unless you put the object inside
> application variable or session variable and persist it.Other wise
> when you are done working with the object it is ready for the garbage
> collector to be collected and when the second request arrives ,if the
> object is collected then you need to create another instance.Am I
> righ?
>
> BTW ReportingServic eProxy is a proxy class of a webservice.
>
> Thanks
>



Nov 19 '05 #7
J-T
Thanks a lot for your nice help
"Marina" <so*****@nospam .com> wrote in message
news:eZ******** ******@TK2MSFTN GP10.phx.gbl...
If the object will be used for read only purposes, then going the static
route is fine.

"J-T" <J-*@microsft.com> wrote in message
news:OO******** ******@TK2MSFTN GP10.phx.gbl...
About the first method,

As you can see ,it is using an static variable ,and I think static
variables are stored in the heap and objects stored on the heap can be
accessed by all threads.My object is a readonly object.what I mean by
read only is that none of the threads are trying to change it ,they only
want to use it,so none of those threads lock the object.Having said all
this,do you still think that I have still thread issue.

Thanks
"Marina" <so*****@nospam .com> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
1. No, it is not right. When it is a static object, it means it belongs
to class type. And there is only one of that. Once it is instantiated,
it stays around for the lifetime of the application. Meaning until
asp.net is shut down or recycled.

2. ASP.NET is multithreaded - and if it wasn't, you would have a very
very slow application. This is why I suggested having the static object
is not a way to go - you have to start worrying about multiple threads
accessing your object at the same time.

"J-T" <J-*@microsft.com> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
> The first way, you will have one instance for the entire asp.net app.
> It will not be garbage collected.
Why it is not gargage collected? Imagine a request makes this object
be created and when the request is done the object is there ,may hang
around for a while and if no one else (no other request) uses that one
,then it has no reference to it and it's ready to be garbage
collected.right ?
> However, you are opening yourself up for potential threading issues.
> If 2 people make a request at the same time, what if both their
> threads are accessing this one instance of the object at the same
> time?

ASP.NET application is a multi-threaded one and there is always
multiple threads working with objects it create,There is no way of
getting rid of multiple threads working at the same time ,right?

Thanks for your reply.

"Marina" <so*****@nospam .com> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
> The first way, you will have one instance for the entire asp.net app.
> It will not be garbage collected.
>
> However, you are opening yourself up for potential threading issues.
> If 2 people make a request at the same time, what if both their
> threads are accessing this one instance of the object at the same
> time? Depending on what your object does, you may need to synchronize
> access to it. Which could potentially slow down your app if it takes a
> long time to complete its work, as well as adding complexity to
> anything using it, because now it has to worry about making sure it is
> safe to access this object.
>
> For asp.net, hands down I would go with way #2. Odds are, the creation
> of this object is not expensive, and it will be garbage collected when
> the request is finished. You aren't really going to see a noticeable
> performance difference, and you will avoid a whole lot of other
> problems.
>
> "J-T" <J-*@microsft.com> wrote in message
> news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
>>I can instantiate my object in my *ASP.NET* application in two ways:
>>
>> A)
>> public sealed class RSSingleton
>> {
>>
>> private static ReportingServic eProxy m_RsProxy=null;
>> static RSSingleton()
>> {
>> m_RsProxy = new ReportingServic eProxy();
>> m_RsProxy.Crede ntials =
>> System.Net.Cred entialCache.Def aultCredentials ;
>> m_RsProxy.Url =
>> ConfigurationSe ttings.AppSetti ngs[Constants.CONFI G_RS_URL] +
>> "/ReportService.a smx";
>> }
>> internal static ReportingServic eProxy Instance{get{re turn
>> m_RsProxy;}}
>> }
>>
>>
>> B)
>> public class RSFactory
>> {
>> //Empty constructor
>> static RSFactory()
>> {
>>
>> }
>> public static ReportingServic eProxy Proxy
>> {
>> get
>> {
>> ReportingServic eProxy rsProxy = new ReportingServic eProxy();
>> rsProxy.Credent ials =
>> System.Net.Cred entialCache.Def aultCredentials ;
>> return rsProxy;
>> }
>> }
>> public static string doSomthing(..)
>> {
>> Proxy.Render(.. .)
>> }
>> }
>>
>>
>> I personally like the second one.Some people say that the second one
>> is not good because everytime you call doSomthing(..) a new instance
>> is created.I do agree with it ,but the first approach in an aasp.net
>> application has the same demrits ,unless you put the object inside
>> application variable or session variable and persist it.Other wise
>> when you are done working with the object it is ready for the garbage
>> collector to be collected and when the second request arrives ,if the
>> object is collected then you need to create another instance.Am I
>> righ?
>>
>> BTW ReportingServic eProxy is a proxy class of a webservice.
>>
>> Thanks
>>
>
>



Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4718
by: Colin Mc Mahon | last post by:
Hi all, I currently use a class to interface with my databases, allowing me to insert, update, delete and retrieve records from the database as methods of the class. I have now created a recordset class and want to in some way instantiate this class via the database class i.e. Set objDbase = New cDatabase
8
775
by: Carel Lotz | last post by:
H We have ported our VB 6 application into VB .NET but are still integrating with a few COM + applications written in VB6 running on our application server (Win 2000 Server). We have the proxies to link to the application server installed but we every now and then get a error when we try to make a call to a component running on the app server. The error message is something like Object reference not set to an instance of an objec at...
5
1309
by: thechaosengine | last post by:
Hi everyone, I've been looking at the various ways to create a data access layer recently. There was one thing in particular that occured to me and I was hoping to garner some experienced insight into the matter. Some people create a DA component that requires instantiation before use. For example: DataAccessComponent dac = new DataAccessComponent(connectionString);
5
2378
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
16
2187
by: gabon | last post by:
Due a big project I would like to create different javascript classes and assign them to divs. But how? :) I know the usage of prototype but given that this could be possible: function newDiv(){...} newDiv.prototype=new div(); and of course it isn't. How to instantiate that class? var newDiv_instance=document.createElement("div");
9
2636
by: the_grove_man | last post by:
I guess my question can go in two directions. I create applications that run multiple queries against a database. Generally speaking in the past I have used a Data Control (calling it dat1) making it invisible and have used this whenever i needed it. dat1.databasename = app.path & "mydatabase.mdb" dat1.recordsource = "my query" dat1.refresh
13
2321
by: Brian | last post by:
I have many similar classes in a project, one for each type of report my app can create. I want to instantiate them based on a value passed in by a scheduler module. Right now I have Sub RunReports(sReport) Select Case sReport Case "CRByDistrict" oReport = New CRByDistrict
4
3667
by: Tomas | last post by:
A newbie question: How can I instantiate objects dynamically in VB.NET. E.g. I have the object 'Player' and I would like to instantiate it with the several instances (James, Gunner, etc.), without in advance knowing how many objects (employee1, employee2, etc) Dim player1 As New Persons.Players Dim player2 As New Persons.Players Dim player3 As New Persons.Players ....
5
1379
by: RyanN | last post by:
Hello, I'm trying to teach myself OOP to do a data project involving hierarchical data structures. I've come up with an analogy for testing involving objects for continents, countries, and states where each object contains some attributes one of which is a list of objects. E.g. a country will contain an attribute population and another countries which is a list of country objects. Anyways, here is what I came up with at first:
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.