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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:28:17+00:00 2026-05-15T16:28:17+00:00

How to use Ninject with a sample code for interface and its implementation like

  • 0

How to use Ninject with a sample code for interface and its implementation like this:

public interface IRepository
{
    // common methods for all content types
    void Insert(BaseContentObject o);
    void Update(BaseContentObject o);
    void Delete(string slug);
    void Delete(ContentType contentType, string slug);
    IEnumerable<BaseContentObject> GetInstances();
    BaseContentObject GetInstance(ContentType contentType, string slug);
    BaseContentObject GetInstance(string contentType, string slug);
    BaseContentObject GetInstance(string slug);
    IEnumerable<string> GetSlugsForContentType(int limit = 0, string query = "");
    ContentList GetContentItems();
    bool IsUniqueSlug(string slug);
    string ObjectPersistanceFolder { get; set; }
}

public class XmlDefaultRepository : IRepository
{
    private ContentType SelectedType;

    public XmlDefaultRepository(string contentType)
    {
        SelectedType = (ContentType) Enum.Parse(typeof(ContentType), contentType);
    }

    public void Insert(Models.ContentClasses.BaseContentObject o)
    {
        throw new NotImplementedException();
    }

    // ...
}

public class PageController : BaseController
{
    private IRepository ContentRepository { get; private set; }

    public PageController(IRepository repository)
    {
        ContentRepository = repository;
    }

    // 
    // GET: /{slug}
    // GET: /Pages/{slug}
    public ActionResult Display(string slug)
    {
        // sample repository usage
        Page page = ContentRepository.GetInstance(slug);
        // ...
    }
}

My code does not contain default constructor because I don’t need one (even if wanted to create it I couldn’t because I always require the content type to be provided.

I cannot make a default constructor because there is logically no default content type to be provided.

This is the exception that Ninject produces when trying to load my ASP.NET MVC page.

*Error activating string

No matching bindings are available, and the type is not self-bindable.

Activation path:

  1. Injection of dependency string into parameter contentType of constructor of type XmlDefaultRepository
  2. Injection of dependency IRepository into parameter repository of constructor of type PageController
  3. Request for IController

Suggestions:

  1. Ensure that you have defined a binding for string.
  2. If the binding was defined in a module, ensure that the module has been loaded into the kernel.
  3. Ensure you have not accidentally created more than one kernel.
  4. If you are using automatic module loading, ensure the search path and filters are correct.*

  • 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-15T16:28:17+00:00Added an answer on May 15, 2026 at 4:28 pm

    You shouldnt need to introduce a default ctor just to please Ninject.

    Assuming you’re using V2, the semantics for how a constructor is chosen are detailed here

    (BTW By default, the string type is not treated as a resolvable type OOTB, but you should be able to Bind ContentType To something and have that constructor invoked).

    If none of the above gets you moving, can you please supply a usage scenario and/or an exception detailing the issue you’re having.

    EDIT: It’s not clear to me at this point that you’re definitely in a situation where you shouldnt be adding a ConstructorArgument ((probably via WithConstructorArgument() IIRC) to your Bind<T>() statement.

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

Sidebar

Related Questions

How to use this functionality in ninject 2.0? MyType obj = kernel.Get<MyType>(With.Parameters.ConstructorArgument(foo,bar)); The With
I am attempting to use bbv.common.EventBroker with Ninject and am running into a few
Ninject looks great, so I'd like to use it in my project. Unfortunately I
I'm building a Silverlight application with Prism, and we'd like to use NInject. I've
In trying to configure ServiceStack.net to use Ninject as its IOC, I am getting
I would like to use Ninject in my WinForms application. I cannot figure out
What would the following example look like re-written to use Ninject? Specifically how would
Can you use Ninject 2.0 with VS2010 RC1?
I am trying to properly use Ninject to inject log4net logging into my MVC3
I'm using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for

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.