开发者

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜