2

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 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

comments and criticisms are welcome

Carlos Cocom
  • 937
  • 1
  • 8
  • 23
  • Take a look at the multiton, maybe this is what you looking for. http://en.wikipedia.org/wiki/Multiton_pattern#C.23 @Carlos and btw the singelton is not a performance pattern. Maybe you should read about it also – sra May 14 '11 at 06:10

1 Answers1

0

Very good approach is to use Dependency Injection. For example Unity.

VikciaR
  • 3,324
  • 20
  • 32
  • thanks, i have helper's class where supply dependency at moment created thats helpers are facade some how DAO, new ServiceXDAO(WebServiceMaster.ServiceXInterface) , new ServiceYDAO(WebServiceMaster.ServiceYInterface). Maybe an good approach is use ServiceLocator but i dont know if that have option for created singleton services – Carlos Cocom May 14 '11 at 14:02
  • Unity can create these objects for you: you can set which lifetime you want (per instance, singleton or define yours). And this functionality you get right of the box. Why reinvent bicycle? So, I don't know why you down vote this answer. For example, _container.Resolve() will return new MyService or already created MyService instance dependent on how you configured Unity. – VikciaR May 16 '11 at 10:41
  • why reinvent bicycle? not exactly, in this case i am using framework 2.0 and with one company extern and they are closed mind about DI, IoC. Really i look something simple but util and thinking about performance in the application. thanks for your comments – Carlos Cocom May 20 '11 at 14:54