ASP.NET MVC using Repository pattern - code review I am just trying to use ASP.NET MVC using repository pattern. Could somebody see If I am doing something wrong here.

Model - Contains the model

public class Contact
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
    }


Repository interface - Interface

    public interface IContactRepository
        {
            void Create(Contact contact);
            void Delete(int contactId);
            void Save(Contact contact);
            Contact Retrieve(int contactId);
            IEnumerable&lt;Contact&gt; Select();
        }


Repository class

public class ContactRepository : IContactRepository
    {
        private AddressBookDb addressBookdb = new AddressBookDb();

        public void Create(Contact contact)
        {
            addressBookdb.Contacts.Add(contact);
            addressBookdb.SaveChanges();
        }

        public void Save(Contact contact)
        {
            Delete(contact.Id);
            Create(contact);
        }

        public void Delete(int contactId)
        {
            Contact contact = Retrieve(contactId);
            if (contact != null)
            {
                addressBookdb.Contacts.Remove(contact);
                addressBookdb.SaveChanges();
            }
        }

        public Contact Retrieve(int contactId)
        {
            return addressBookdb.Contacts.FirstOrDefault&lt;Contact&gt;(c =&gt; c.Id == contactId);
        }

        public IEnumerable&lt;Models.Contact&gt; Select()
        {
            return addressBookdb.Contacts.ToList&lt;Contact&gt;();
        }
    }


Controller class

public class ContactController : Controller
    {
        IContactRepository contactRepository = null;
        public ContactController() : this (new ContactRepository())
        {

        }

        public ContactController(IContactRepository contactRepository)
        {
            this.contactRepository = contactRepository;
        }

        [HttpPost]
        public ActionResult Edit(Contact contact)
        {
            if (ModelState.IsValid)
            {
                contactRepository.Save(contact);
                return RedirectToAction("Index");
            }
            return View(contact);
        }
}
You code shows not only your definition of your repository but also it's usage.

What worries me is that i don't see how the DbContext (AddressBookDB in this case) is disposed off.

I think i'd rather pass in the AddressBookDB object as a paramter to the repository constructor for usage so you can ensure it is diposed off properly by creating it in a using block.