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 9160025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:38:14+00:00 2026-06-17T13:38:14+00:00

So i started looking into Dependency Injection and Ioc Containers. From what i know

  • 0

So i started looking into Dependency Injection and Ioc Containers. From what i know DI is used to avoid tighly coupling the classes or avoid creating the depending object out of the consumer class. But isnt it unnecessary to use DI if we are using that object only in one class?
Now my problem is how do i initialize my Entity model with unity?
Currently i use constructor injection as usual to initialise my Entity model as

public class Food
{
    private FoodContext _foodContext

    public Food(FoodContext food)
    {
        _foodContext=food
    } 
}

Now here FoodContext is my entity framework model, how do I initialise with unity? I may want to replace the model with another in future, so it may become a headache to find and replace all the reference across the entire solution.
So in order for doing that, am I going to create an interface first? I mean that autogenerated class contains lots and lots of properties and methods. that doesn’t seem right.

So what is the normal practice of doing this?

  • 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-06-17T13:38:15+00:00Added an answer on June 17, 2026 at 1:38 pm

    To achieve that, take a look at the Repository pattern
    The main Idea of Repository pattern : It abstracts the DataProvider using an interface and called using dependency injection that leads to two main benefits : Low coupling and Testability.

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

Sidebar

Related Questions

just started looking into knockout.js library. I'm just curious to know if it is
I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx
I am from J2EE background and recently started looking into .Net. I am wondering
When I first started looking into Rails and Django I was steered away from
I started looking into PhoneGap yesterday and created a simple marble rolling around while
I've started looking into a few larger server-app frameworks that would be able to
I recently started looking into building web applications using .NET MVC and I stumbled
I am looking into displaying an activity when the service is first started so
I am just getting started couchdb and have been looking into writing couch apps.
I started looking into the designer file of one of my Forms and noticed

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.