2

I have WCF service that is hosted in IIS.

I need to initialize once several things that will exists through all calls to the services.

Where is the appropriate place to make those initializations ?

Thanks for assistance .

Night Walker
  • 20,638
  • 52
  • 151
  • 228

3 Answers3

4

Use constructor (either that of BaseService or actual service class) to initialize these properties

Bear in mind that when WCF service is configured for Per-Call instance mode, Service instance will be created for each client request

If is not strictly needed don't use any Singleton strategy:

Singleton WCF services should hardly ever be used- Singletons are the enemy of scalability! They only make sense in weird scenarios- logging to a single file, a single communications port or hardware device.

Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
1

You can initialize them in static constructor or using Container's with Lifetime manager.

Singleton Per Call Context (Web Request) in Unity

Community
  • 1
  • 1
Boris Modylevsky
  • 3,029
  • 1
  • 26
  • 42
1

If your WCF service is configured to use ASP.NET Compatibility Mode, then just initialize them in Application_OnStart in Global.asax.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76