Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ObjectContext class not derive from some Interface?

I consider folks at MS way more smarter than I am. I was trying to build/test a repository which almost follows this approach except that I want to loosely couple the ObjectContext dependency inside the repository. I found out that in order to do decouple this I need to jump a lot of hoops as shown in this article.Even this approach is difficult to work with when

  1. You have an edmx from an existing database
  2. You have a generic repository built around the ObjectContext interface and IObjectSet
  3. While unit testing you want to fake out this object context and keep all the operations in memory. Think testing Repositories.

Now the real question, why did the creators of ObjectContext decide not to have IObjectContext ?

I hope my question makes sense, I will be glad if someone can prove that it doesnt and shows me the way.

Thanks in advance!

like image 429
Perpetualcoder Avatar asked Sep 06 '10 05:09

Perpetualcoder


1 Answers

Since the context is a partial class, you can easily add an interface to it in a separate file: public partial class YourContext : IMyCustomInterface, and you can put in IMyCustomInterface any signatures you want to use from the generated ObjectContext.

Or you could go about the (generally) more recommended way, which is to abstract further than the ObjectContext into Repositories like in this blog post(that entire series of posts is interesting and relevant) or this one.

like image 52
Alex Paven Avatar answered Sep 25 '22 16:09

Alex Paven