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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:31:22+00:00 2026-06-17T06:31:22+00:00

I have a project called Infrastructure , which contains an interface IRepository public interface

  • 0

I have a project called Infrastructure, which contains an interface IRepository

public interface IRepository<T>
{
    /// <summary>
    /// Adds the specified entity to the respository of type T.
    /// </summary>
    /// <param name="entity">The entity to add.</param>
    void Add(T entity);

    /// <summary>
    /// Deletes the specified entity to the respository of type T.
    /// </summary>
    /// <param name="entity">The entity to delete.</param>
    void Delete(T entity);
}

In my solution, i have two other projects

  • Application.Web
  • Application.Web.Api
  • Infrastructure

Both projects, contains an implementation of the IRepository interface

public class EFRepository<T> : IRepository<T>
{
    // DbContext for Application.Web project
    ApplicationWebDbContext _db;
    public EFRepository(ApplicationWebDbContext context)
    {
        _db = context;
    }

    public void Add(T entity) { }
    public void Delete(T entity) { }
}

public class EFRepository<T> : IRepository<T>
{
    // DbContext for Application.Web.Api project
    ApplicationWebAPIDbContext _db;
    public EFRepository(ApplicationWebAPIDbContext context)
    {
        _db = context;
    }

    public void Add(T entity) { }
    public void Delete(T entity) { }
}

Both implementations works with different DataContexts.

How can I bind this in ninject?

private static void RegisterServices(IKernel kernel)
{
    // bind IRepository for `Application.Web` project
    kernel.Bind(typeof(IRepository<>)).To(typeof(Application.Web.EFRepository<>));

    // bind IRepository for `Application.Web.Api' project
    kernel.Bind(typeof(IRepository<>)).To(typeof(Application.Web.Api.EFRepository<>));    
}
  • 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-17T06:31:23+00:00Added an answer on June 17, 2026 at 6:31 am

    There are several appoaches to resolve such situations

    Named binding

    Simplest, just provide name for dependency:

    kernel
            .Bind(typeof(IRepository<>))
            .To(typeof(WebApiEFRepository<>))
            // named binding
            .Named("WebApiEFRepository");
    

    And resolve it using this name. Name cound be found in configuration: web.config for example:

    var webApiEFRepository = kernel.Get<IRepository<Entity>>("WebApiEFRepository");
    

    Contextual binding

    Find from injection context what type to bind. In your example based on target namespace

    kernel
        .Bind(typeof(IRepository<>))
        .To(typeof(WebDbRepository<>))
        // using thins binding when injected into special namespace
        .When(request => request.Target.Type.Namespace.StartsWith("Application.Web"));
    

    Get dependency from kernel:

    // WebDbRepository<> will be injected
    var serice = kernel.Get<Application.Web.Service>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project called MyApp.DataAccess which contains several database contexts. This started as
I have a project called Data which is a data layer. In this project,
I use LINQ-SQL as my DAL, I then have a project called DB which
In my domain I have something called Project which basically holds a lot of
I have an ASP.NET web application project which references another project called ModusCore (or
We have a project with 3 subprojects one of which is called bldfiles. Each
say that i have a project which lies in a folder called 'bin', and
in the tomcat6 server I have a project that contains a servlet, I called
This is homework, just so that's mentioned. I have project called AdventCalendar, which is
I have one project (called EJB server) that contains X-Doclet annotated EJB service and

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.