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 controllers ?
Why was this downvoted?
SLaks
2009-11-25 14:57:28
It shouldn't be downvoted.
Mike C.
2009-11-25 16:41:19
A:
Dependancy Injection (or create a base class for all your controllers)
David Kemp
2009-11-25 13:19:06
Creating a base class won't share the instance, which I assume he's trying to do.
SLaks
2009-11-25 13:19:45
+2
A:
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.
queen3
2009-11-25 16:39:00