well hello everybody
i have one project with multiples web services so i created various singleton class thinking in performance. now i think create one singleton class and that have the instances of my webservices
example
public static WebServiceMaster
{
internal ServiceX WebX;
internal ServiceY WebY;
......
public static WEbServiceMaster GetInstance()
.....
}
what think about that? is that bad?
Well, finally that is done. I know that is not perfect
Public NotInheritable Class ServiceProxySingleton
Private _services As IDictionary(Of ProxyServicesEnum, IServiceDispatcher) = New Dictionary(Of ProxyServicesEnum, IServiceDispatcher)
Private _dbRepository As IDACommon
Private Sub New()
_dbRepository = New DACommon()
LoadServices()
End Sub
Private Sub LoadServices()
_services.Add(ProxyServicesEnum.eActivity, New ActivityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eAvailability, New AvailabilityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eBrochure, New BrochureServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eInformation, New InformationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMeetingRoom, New MeetingRoomServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMembership, New MembershipServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eName, New NameServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eReservation, New ReservationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eResvAdvanced, New ResvAdvancedServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eSecurity, New SecurityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eStayHistory, New StayHistoryServic开发者_C百科eImp(_dbRepository))
_services.Add(ProxyServicesEnum.ePostXml, New PostXmlServiceImp(_dbRepository, ConfigurationServiceSingleton.GetInstance.GetPostXmlConfig))
_services.Add(ProxyServicesEnum.eOxiHttp, New OxiServiceImp(_dbRepository))
End Sub
Public ReadOnly Property Service(ByVal serviceEnum As ProxyServicesEnum) As Object
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum)
End If
Return Nothing
End Get
End Property
Public ReadOnly Property GetMeta(ByVal serviceEnum As ProxyServicesEnum) As IDictionary(Of String, MethodIdentityAttribute)
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum).MetaInfo
End If
Return Nothing
End Get
End Property
Public Shared Function GetInstance() As ServiceProxySingleton
Return NestedPrWireService._instance
End Function
Class NestedPrWireService
Friend Shared ReadOnly _instance As ServiceProxySingleton = New ServiceProxySingleton()
Shared Sub New()
End Sub
End Class
End Class
comments and criticisms are welcome
Very good approach is to use Dependency Injection. For example Unity.
精彩评论