ASP.NET MVC controllers static methods

后端 未结 1 465
盖世英雄少女心
盖世英雄少女心 2020-12-09 06:07

A discussion came up at work recently about why ASP.NET MVC doesn\'t use static methods for its controller methods. Whilst I was on the side of the fence against us

相关标签:
1条回答
  • 2020-12-09 06:45

    While I don't know minds of those that designed the ASP.NET MVC Framework here is the big one for me:

    An instance controller is instantiated once per request, multiple requests can be happening simultaneously. If a controller is static then any state on the controller is shared across all requests simultaneously. You probably don't want that. Updating that shared state becomes a minefield of locking contention, possible deadlocks and very hard to track bugs if locking isn't implemented properly.

    In short, a static controller would be a nightmare to work with.

    0 讨论(0)
提交回复
热议问题