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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:32:45+00:00 2026-06-15T16:32:45+00:00

NInject noob here. Sorry about the wall of code that follows, but there’s a

  • 0

NInject noob here. Sorry about the wall of code that follows, but there’s a lot of moving parts here.

I’ve got a namespace that defines the implementation agnostic persistance interfaces I want to program to. The top level interface looks like this:

namespace Common.PersistenceStrategy
{
    public interface IPersistenceStrategy
    {
        IPersistenceRepositoryInstructionResult Commit();

        IPersistenceRepository<T> repositories<T>() where T : class;
    }
}

The general EF implementation of this interface goes in it’s own namespace & project:

namespace Common.PersistenceStrategy.EF
{
    public class EFPersistenceStrategy : IPersistenceStrategy 
    {
        protected DbContext _context;

        public EFPersistenceStrategy(DbContext context)
        {
            _context = context;
        }
        //Other Implementation stuff...
}

The project-specific implementation gets it’s own namespace & project. The idea is to override some of the generic/default EF behaviour, and act as the single point of EF-dependance in the current project.

namespace MyProject.DAL
{
    public class MyProjectPersistenceStrategy : EFPersistenceStrategy
    {
        public MyProjectPersistenceStrategy() : base(new MyProjectDbContext())
        {}
        //project specific implementation overrides
    }
}

Getting there…
In the website that’s to consume/use the MyProjectPersistenceStrategy, the controllers are inheriting from this class:

namespace MyProject.Site.Controllers
{
    public abstract class ControllerWithUnitOfWork : Controller
    {
        [Inject]
        public IPersistenceStrategy _persistenceStrategy { get; set; }
        //other implementation stuff
    }
}

And finally, here’s the NInject kernel code to wire IPersistenceStrategy to MyProjectPersistenceStrategy:

private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<IPersistenceStrategy>().To<BlackoutPersistenceStrategy>();

    }

So, I’m getting two error messages related to the kernel binding portion:

Error   3   The type 'Common.PersistenceStrategy.EF.EFPersistenceStrategy' is defined in an assembly that is not referenced. You must add a reference to assembly 'Common.PersistenceStrategy.EF...

Error   6   The type 'MyProject.DAL.MyProjectPersistenceStrategy' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax<T1>.To<TImplementation>()'. There is no implicit reference conversion from 'MyProject.DAL.MyProjectPersistenceStrategy' to 'Common.PersistenceStrategy.IPersistenceStrategy'.   C:\dev\Blackout\Blackout.Site\App_Start\NinjectWebCommon.cs

MyProject.Site has already got references to MyProject.DAL and Common.Persistence, which is fine and sensible.

Both errors go away if I reference Common.Persistence.EF from my web project. That’s not really a runner though, since the whole point of the dependency injection effort was to isolate the dependency on EF to a single module within the current project. It seems that NInject can’t walk the relationship chain between MyProjectPersistenceStrategy and IPersistenceStrategy unless it can see the whole class tree between the two? Is there a direct solution to this, or am I trying to do the wrong thing here? Cheers.

  • 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-15T16:32:45+00:00Added an answer on June 15, 2026 at 4:32 pm

    It is not Ninject issue. It is build process (compilation) issue. You cannot build your web project if reference to Common.PersistenceStrategy.EF.EFPersistenceStrategy is missing, because MyProject.DAL.MyProjectPersistenceStrategy inherits from class defined there.

    Comment

    Imagine the bin folder after you build your application. It must contain Common.PersistenceStrategy.EF.dll to run your application (actually it must contain all required dlls which are not registered in GAC). Because of that, MsBuild wants you to declare the reference to that project dll, because he reads from the *.csproj file which dlls are needed to build the application. It seems to me, that <ProjectReference Include="..\MyProject\MyProject.csproj"> inside the *.csproj just points MSBuild that it should first run build on that referenced build script, but does not looks on another references inside it. In fact if you look on Properties of referenced project in VS, the path points to bin folder of that project.

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

Sidebar

Related Questions

Pardon me if there's a similar question somewhere on here already, but I couldn't
I'm using Ninject in my MVC 3 project and that works fine, but I
I am using Ninject for DI. I have Ninject Modules that bind some services
Using Ninject 2 MVC 3. Correct me if i am wrong but ive seen
I've hooked up Ninject (correctly) to bind NLog. Here is my RegisterService method in
I am implementing Ninject dependency injection in an existing MVC 2 application that uses
In Ninject, declaring a binding in singleton scope means that the same object will
The Ninject project consists of the Ninject Core library and lot (~17) of extension
I am familiar with Ninject, but not Spring.Net. I am trying to determine if
I'm using Ninject with an MVC app, also using EF4.1 Code First. I'm getting

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.