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
  • 19,742
  • 49
  • 147
  • 222

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
  • 25,679
  • 6
  • 57
  • 68
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
  • 2,877
  • 1
  • 25
  • 40
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
  • 31,619
  • 8
  • 58
  • 72