can I use only one instance of IDbContext in the whole app?

Apr 22, 2012 at 6:58 AM

i create a singleton for application.

it seems nothing wrong happened...

or any best practices?

Apr 22, 2012 at 7:27 AM

Do you use MVC or WebForm? I will make a small app that shows the best practice.

I do not recommend using a singleton because this will not work with transactions. You will not get an error but when your application get more users then you will start experiencing strange behaviors. Even if you don't transactions now, but sooner or later you will and then you will need to refactor everything so its better to it correctly from the beginning. So best practice is one per request.

Apr 22, 2012 at 12:13 PM


yeah...I find that when I use TPL, it sometimes work weird...

thank you.