多个网络服务如此多单身

时间:2011-05-14 05:56:07

标签: vb.net web-services

大家好吧

我有一个带有多个Web服务的项目,所以我在性能上创建了各种单例类思维。现在我认为创建一个单例类并且具有我的webservices的实例

例如

public static WebServiceMaster
{
  internal ServiceX WebX;
  internal ServiceY WebY;
  ......
  public static WEbServiceMaster GetInstance()
  .....  
}
怎么想的呢? 那很糟糕吗?

好吧,最后就完成了。我知道那不完美

 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 StayHistoryServiceImp(_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

欢迎提出意见和批评

1 个答案:

答案 0 :(得分:0)

非常好的方法是使用依赖注入。例如Unity