nev.angelova
nev.angelova

Reputation: 94

Unit Of Work + Repository Pattern - one data instance per controller

I don't understand why with Unit Of Work + Repository Pattern I can use only one data instance (which wraps the DbContext and provides repositories with the relevant entities) per controller in MVC. Without the pattern I need to make an instance of DbContext in every action because of the concurrency problem.

Thanks in advance!

Upvotes: 0

Views: 131

Answers (1)

Ross Dargan
Ross Dargan

Reputation: 6021

You should have one DbContext per request from the user (which make sense if you think about it).

This is not per controller however - if you have it is working this way for you I'd guess you have the lifecyle set up incorrectly on your Inversion of control container.

A few code samples might help.

Upvotes: 1

Related Questions