Long running process, EF, Prism, Unity? RRS feed

  • Question

  • Hi,

    I am curious to know, what is the right way to go?

    I implemented IUnit Of Work and register as singleton by using UnityBlock. There's no problem with Web APP(ASP.NET) but my app is Desktop APP(StateFull).

    If I don't register as singleton then I lost the IUnit Of Work Pattern, That means the many DbContext instance will be created while the app is running.

    If I register as Singleton then, likely saying I am pulling almost all data from MS-SQL to memory!(I don't lose the Unit Of Work Pattern).

    Any thought welcome!. I hope someone from EF team could give me the right way to go. No one expert with EF than EF Team.

    There's no problem if we have middle tier by using WCF, Web APIs etc but I don't use any of those tiers.

    Shall I clear the DbContext for specified time or load as no track?



    Wednesday, October 21, 2015 8:27 AM


  • For me, I would not choice to use singleton or the IUnit Of Work Pattern, because DbContext itself implements the Unit of work pattern, and if using the IUnit of work, the DbContext usage would just create another abstraction on an existing abstraction, that's just too much code IMO. There is another issue in the current design: the repository calls SaveChanges on the DbContext. This means that it makes XXXRepository responsible to commit all the modification it makes on the unit of work, not just the modifications on the XXX entities the repository is responsible for.

    >> Shall I clear the DbContext for specified time or load as no track?

    If a dbdontext is only for query purpose, you could set it to be without track to improve the performance. If the dbcontext would have other business logic as add/update/delete, it is necessary to turn on the track and it would help do a check when submitting you data to database.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Fred Bao Wednesday, November 4, 2015 3:06 AM
    • Marked as answer by Fred Bao Thursday, November 5, 2015 2:39 AM
    Thursday, October 22, 2015 1:57 AM