问题
we have a solution converted to ASP MVC, which is growing bigger and bigger.
The problem now is: The startup of the application takes around 15+ seconds, because the application needs to pre-cache a lot of stuff from a database.
Now, in ASP MVC the problem is, every time we change something in a controller, the whole app is shut down and restartet, all the stuff in global.asax is executed again (as if the app comes from a "cold start"
Imagine: You write a simple if-condition, by accident you put in the wrong parameters -> you have to correct the if-condition. --> the WHOLE app is restartet.
So, we have to wait 15+ seconds every time we change even small things.
In old ASP.NET, you placed most of the code in .aspx-files which were just re-interpreted, but the whole app wasn't shut down etc.
Is there a work around for this? Like -lets call it- "interpreted controllers" instead of compiled controllers?
This ASP MVC behaviours makes it really annoying, the current workaround is to put as much stuff as possible into the views, which is bad practice - but hey, it helps us since we don't have to wait 15+ seconds until the controller is recompiled and the app restarted.
Any idea?
Regards
回答1:
because the application needs to pre-cache a lot of stuff from a database
To me, this is the problem. Not the thing itself (it is pretty normal), but the fact that you aren't short-circuiting anything, for example dumping the cached data into a store or... for development purposes, the file system. I'm going to let you into a little secret of what happens when I debug locally:

Basically, it cheats: only in development, to avoid running any expensive operations, during startup, it first checks for a file on the local disk (with the right name), and gets the critical data it needs from there, rather than the database; if it has to hit the database, it stores the data it fetched afterwards. Obviously, with some mechanism to flush both the file and the in-memory store, so that actual data can be fetched if required.
It isn't a magic wand, but it helps. The other thing to do, obviously, is to speed up the initial load time. I would be surprised if this was impossible in your case.
回答2:
Have been on a Microsoft Event a couple of weeks ago, focus was ASP vNext.
We discussed also this behaviour: It is actually by design in versions of ASP/MVC prior to vNext.
In next version "ASP vNext", you can change controller code on the fly, without the need of recompiling the whole project (thus, preventing to shut down the whole webserver process)
Good news - at least for the future ;-)
来源:https://stackoverflow.com/questions/25550584/asp-mvc-4-x-recompile-project-every-time-how-to-fix