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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:09:28+00:00 2026-06-14T15:09:28+00:00

My understanding of WithConstructorArgument is probably erroneous, because the following is not working: I

  • 0

My understanding of WithConstructorArgument is probably erroneous, because the following is not working:

I have a service, lets call it MyService, whose constructor is taking multiple objects, and a string parameter called testEmail. For this string parameter, I added the following Ninject binding:

string testEmail = "test@example.com";
kernel.Bind<IMyService>().To<MyService>().WithConstructorArgument("testEmail", testEmail);

However, when executing the following line of code, I get an exception:

var myService = kernel.Get<MyService>();

Here is the exception I get:

Error activating string No matching bindings are available, and the
type is not self-bindable. Activation path:
2) Injection of
dependency string into parameter testEmail of constructor of type
MyService
1) Request for MyService

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 constructor
arguments, ensure that the parameter name matches the constructors
parameter name.
5) If you are using automatic module loading, ensure
the search path and filters are correct.

What am I doing wrong here?

UPDATE:

Here is the MyService constructor:

[Ninject.Inject]
public MyService(IMyRepository myRepository, IMyEventService myEventService, 
                 IUnitOfWork unitOfWork, ILoggingService log,
         IEmailService emailService, IConfigurationManager config,
         HttpContextBase httpContext, string testEmail)
{
    this.myRepository = myRepository;
    this.myEventService = myEventService;
    this.unitOfWork = unitOfWork;
    this.log = log;
    this.emailService = emailService;
    this.config = config;
    this.httpContext = httpContext;
    this.testEmail = testEmail;
}

I have standard bindings for all the constructor parameter types. Only ‘string’ has no binding, and HttpContextBase has a binding that is a bit different:

kernel.Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(new HttpContext(new MyHttpRequest("", "", "", null, new StringWriter()))));

and MyHttpRequest is defined as follows:

public class MyHttpRequest : SimpleWorkerRequest
{
    public string UserHostAddress;
    public string RawUrl;

    public MyHttpRequest(string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output)
    : base(appVirtualDir, appPhysicalDir, page, query, output)
    {
        this.UserHostAddress = "127.0.0.1";
        this.RawUrl = null;
    }
}
  • 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-14T15:09:29+00:00Added an answer on June 14, 2026 at 3:09 pm

    With the statement:

    var myService = kernel.Get<MyService>();
    

    You are trying the resolve MyService and because the MyService type is not registered in your kernel Ninject will treat it as a self bound type.

    So it won’t use your WithConstructorArgument to resolve the "testEmail" because it will be only used with Bind<IMyService>() that is why you’re getting the exception.

    So if you have registered your MyService with:

    string testEmail = "test@example.com";
    kernel.Bind<IMyService>().To<MyService>()
          .WithConstructorArgument("testEmail", testEmail);
    

    Then you should resolve it through the registered interface (IMyService):

    var myService = kernel.Get<IMyService>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Understanding that I should probably just dig into the source to come up with
My understanding of regex and working with strings in php is poor at best
(Understanding of VB.NET: Intermediate) I have 60 Comboboxes on a 10 tabs. I want
My understanding of DataBinding is still at the working on it level, so here
My understanding is any method which does not modify state of the constaining class
I finally got some understanding of how Ninject handles DI, but have faced the
My understanding of Dart leads me to believe that this 'cast' should not affect
Understanding that if someone had JavaScript disabled the site would not work then is
My understanding is that, in keeping with Interbase v6, Firebird 2.5 does not support
My understanding of the Command Pattern is that you simply have 1 virtual method

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.