views:

38

answers:

1

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!

+1  A: 

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.

Alex Paven