Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6942787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:04:13+00:00 2026-05-27T13:04:13+00:00

I prefer creating my own DB, setting up indexes, unique constraints etc. Generating the

  • 0

I prefer creating my own DB, setting up indexes, unique constraints etc. Generating the domain model from the database is a cinch with the edmx Entity Framework designer.

Now I’m interested in setting up some repositories an using Dependency Injection. I’ve looked at some articles and posts on StackOverflow and seem to focus on the code-first approach. It is pretty slick how you can create a generic repository to handle the CRUD and use Dependency Injection to choose the implementation details.

I’d like to do the same thing, but it seems that the domain model generated by the edmx process inherits concrete classes instead of implementing interfaces (ObjectContext/ObjectSet as opposed to IObjectContext/IObjectSet).

Does anyone have any resources they can point me to on how I might use Dependency Injection when utilizing the db-first/code generation technique?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:04:14+00:00Added an answer on May 27, 2026 at 1:04 pm

    Maybe I am misunderstanding your question, but the fact that the EDMX generates code that inherits from ObjectContext doesn’t stop you from using dependency injection. It sounds like you are worried about not being able to inject your ObjectSet into your Repository, but that isn’t quite the way it is designed to be used.

    With a generic repository pattern such as the one found here, the IRepository interface is the thing that you inject into your ViewModels/Controllers/Whatever.

    So, you don’t inject an IObjectContext or IObjectSet into your Repository; instead, you inject your IRepsoitory into your classes that need it, and you provide an implementation of the IRepository interface that uses your ObjectSet. You can then mock your IRepository interface for testing, or switch to a completely different concrete repository implementation, without affecting any of your other code.

    We are currently doing this exact same thing with EF4 DB-first and the repository pattern I linked above, and it is working quite nicely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a programming language from scratch in C, and I'd prefer not to
which method do you prefer for creating dynamic sql queries? formating or streaming? Is
How would you go about creating a vector class in Delphi? I would prefer
I'm a fan of SVN and I am comfortable setting up my own svn
While creating DOJO Components when should we prefer declarative approach and programatic approach?
I'm creating a standard 'framework' in PHP for my own projects. On this point
We are creating MVC3 applications. We are using default editors and model state validation.
I am Creating a web application that will get homework from schools website. I
I am creating a custom control(deriving from Control ) and want to define a
I'm creating my own blog in PHP and want to know your opinions on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.