Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller - ASP.NET MVC - Does more than one instance of a controller get created per App-Domain? If so under what conditions?

Tags:

c#

asp.net-mvc

Does more than one instance of a controller get created per App-Domain? If so under what conditions?

like image 331
Joshua Enfield Avatar asked Jul 01 '11 19:07

Joshua Enfield


People also ask

Can you have more than one controller in MVC?

In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation.

What is the controller responsible for in an ASP.NET MVC application?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.

Can a controller have multiple repositories?

You could instantiate a new context in the repository, but then if you used multiple repositories in one controller, each would end up with a separate context. Later you'll use multiple repositories in the Course controller, and you'll see how a unit of work class can ensure that all repositories use the same context.

Can we have multiple views for single controller?

Yes You can use multiple View in one Controller. so I have one controller and 2 views. Welcome to StackOverflow! While answers are always appreciated, this question was asked 6 years ago, and already had an accepted solution.


1 Answers

A new instance of a controller is created for each request by MVC, so you may end up with multiple instances running on different threads.

There is nothing stopping you from creating multiple instances yourself.

The controller should be stateless.

like image 171
Jakub Konecki Avatar answered Sep 23 '22 01:09

Jakub Konecki