1

How can I use ServiceBehaviorAttribute in my Web API 2 project to create & recycle instance context object on every request? I tried to set it traditional way by configuring in web.config but didn't work. I think I may need to set custom attribute so any suggestion/thoughts are appreciated!

  [ServiceBehaviorAttribute(InstanceContextMode = InstanceContextMode.PerCall)] 

I am new to Web API so not having much exposure on it.

seUser
  • 1,093
  • 2
  • 10
  • 21
  • That attribute may have worked back when Web API ran on top of WCF, certainly not with ASP.NET Web API 2. The latter does create an instance of your controller per request by default anyway. So, are you using Web API, and if so: which version? – CodeCaster Feb 04 '15 at 20:48

1 Answers1

3

The ServiceBehaviorAttribute is in the System.ServiceModel namespace and is used exclusively for WCF not for Web API. The following link seems to address your issue: Programmatically set InstanceContextMode

Community
  • 1
  • 1
Seymour
  • 7,043
  • 12
  • 44
  • 51