Reputation: 26048
I have some questions regarding a bootstrapper class. I am using ASP.NET MVC 3
.
Is it still wise to use a bootstrapper in MVC3 to reduce the amount of code in the global.asax file?
What exactly must be loaded in the boostrapper besides the registering of routes? If I want to load site-wide settings (loaded from a database), do I do that here? If this is the case then do I need to inject these settings into each controller? If it gotten in the bootstrapper, how are these values retained?
I am looking for code/articles on how to use Autofac with my bootstrapper. I can only find for Ninject. Has anyone got some code or articles for me?
I found these 2 good articles:
I am trying to accomplish something like:
protected void Application_Start()
{
Bootstrapper.Run();
}
Upvotes: 2
Views: 1722
Reputation: 16378
Is it still wise to use a bootstrapper in MVC3 to reduce the amount of code in the global.asax file?
I'm using let's say a bootstrapper (in fact various start up tasks executed in a particular order) in every web applciation. I put in those tasks all the things I need to be setup: from routes and global filters, to setup the DI container, loading settings from the db (after setting up the DI container) and so on.
Basically everything that you could have put in global.asax.cs Application_Startnow resides as tasks in a Start Up directory, and each task is a simple class marked as a startup task (I'm using my own toolkit for that). The benefits of a bootstrapper is the easy mantainance of the those tasks, it has no implicit connection with an IoC Container, however setting up the container is usually something that is executed when the app starts.
If I want to load site-wide settings (loaded from a database), do I do that here
Only if the settings are static or required to configure the app. It pretty much depends on the type of settings and the type of app. There isn't a clear and definite answer.
If this is the case then do I need to inject these settings into each controller
You don't inject settings in a controller, you inject dependecies and that's the IoC container's job.
If it gotten in the bootstrapper, how are these values retained?
The bootstrapper is used only once when app starts, to configure the app then it's out. It shouldn't retain values. You may be thinking about settings but even if the bootstrapper loads them, those settings are stored in a different place, usually a cache.
Upvotes: 1