Should We Instantiate Data Context & Repository In Controller?

Should We Instantiate Data Context & Repository In Controller?

I have an ObjectContext and a Repository that gets passed the ObjectContext. I then use the repository to make calls. I want to use dependency injection to not always have to instantiate the ObjectContext and Repository. What "object" would I group the context / repository into?

using (MOSContext db = new MOSContext()) {     IUserRepository users = new UserRepository(db);      // Do stuff with users. } 

Is this bad to do the above? Ideally, I'd like to be able to create "some object" that acts like the ObjectContext, but has accessors to all repository interfaces:

using (IDAL dal = IoC.Resolve<IDal>()) {     dal.Users.GetById(myId);     dal.Profiles.Add(new Profile()); } 

Then using DI, I can register the context and all implementations for each repository interface.

MVC2 client/server validation of DateTime/Date using DataAnnotations


how do i get the content of this div using jquery
Yes, it's bad to new up OCs in the controller. mvc dropdown problemYes, it's better to use DI to return an instance of an interface not strictly tied to the EF. How do you fill in a resource string at run-time?. mvc user login remembering problem You should have one instance of the OC per request, not per method. Jquery datepicker showing previous date in MVCMost DI containers have a request-scoped lifetime feature out of the box.. window.location.href duplicate url address mvc c# javascript web.config

52 out of 100 based on 47 user ratings 162 reviews