J
J-T
I can instantiate my object in my *ASP.NET* application in two ways:
A)
public sealed class RSSingleton
{
private static ReportingServiceProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServiceProxy();
m_RsProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
m_RsProxy.Url =
ConfigurationSettings.AppSettings[Constants.CONFIG_RS_URL] +
"/ReportService.asmx";
}
internal static ReportingServiceProxy Instance{get{return m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{
}
public static ReportingServiceProxy Proxy
{
get
{
ReportingServiceProxy rsProxy = new ReportingServiceProxy();
rsProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
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 ReportingServiceProxy is a proxy class of a webservice.
Thanks
A)
public sealed class RSSingleton
{
private static ReportingServiceProxy m_RsProxy=null;
static RSSingleton()
{
m_RsProxy = new ReportingServiceProxy();
m_RsProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
m_RsProxy.Url =
ConfigurationSettings.AppSettings[Constants.CONFIG_RS_URL] +
"/ReportService.asmx";
}
internal static ReportingServiceProxy Instance{get{return m_RsProxy;}}
}
B)
public class RSFactory
{
//Empty constructor
static RSFactory()
{
}
public static ReportingServiceProxy Proxy
{
get
{
ReportingServiceProxy rsProxy = new ReportingServiceProxy();
rsProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
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 ReportingServiceProxy is a proxy class of a webservice.
Thanks