shared model across controllers
right now in each of my controller classes i am instantiating a new Repository class to access my DB. Is there a way i can simply create this once (a single repository instance shared across all controllers) and pass into all contr开发者_JAVA百科ollers ?
ControllerBuilder.Current.SetControllerFactory(new MyOwnControllerFactory());
In your factory you can set up your repository and pass to ALL controllers.
But of course you better use IoC containers. They have option to create repository once per request / once per app lifetime.
You could make it a singleton.
Dependancy Injection (or create a base class for all your controllers)
精彩评论