A day with .Net

My day to day experince in .net

Instance members of an ActionFilter attribute is not thread safe – MVC

Posted by vivekcek on June 26, 2016

I was trying to inject a dependency to my filter attribute via Ninject’s property injection.The injected instance was using a database connection too.
And one of the ajax polling call was hitting this attribute every 10 seconds.
Strange i got some thread concurrency issue and site went down.
Later i found that in MVC for each request a controller is created, but for each request the same instance of filter attribute is reused.

You can test this via putting break points in the constructor of controller and attribute.

1

2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s