vendredi 3 mars 2017

What's a good pattern for having the EF context persist on web applications through all tiers?

Although it seems a requirement for IoC, I feel it's not a good option to have the EF context available only to the bottommost, the persistence tier.

Doing so I very often find code that's converting an IQueriable's data into a List<T> because the context is closed from within the Repository functions, thereby losing the Linq advantage of not holding all the queried data in memory.

To me it makes more sense to create a context on request start and close it when the request has finished rendering.

Are there any patterns that have been developed for ASP.NET WebForms a/o ASP.NET MFC/Web API dealing with the requirement of transparently (and unit test friendly) administering EF contexts from the uppermost tier?

I'm asking this question particularly because ASP.NET changes threads while executing the request pipeline.

Aucun commentaire:

Enregistrer un commentaire