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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:10:35+00:00 2026-05-28T02:10:35+00:00

In Ninject3 there’s a new .ToConstructor feature . As described, it helps to strongly-type

  • 0

In Ninject3 there’s a new .ToConstructor feature.

As described, it helps to strongly-type constructor arguments like:

Bind<IMyService>().ToConstructor(
    ctorArg => new MyService(ctorArg.Inject<IFoo>(), ctorArg.Inject<IBar>()));

What’s actually the difference between using .ToConstructor and .ToMethod in an almost the same way:

Bind<IMyService>().ToMethod(
    x => new MyService(x.Kernel.Get<IFoo>(), x.Kernel.Get<IBar>()));

Is it just a syntax sugar to avoid using Kernel.Get<>() or is there something more that I’m missing?

  • 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-28T02:10:35+00:00Added an answer on May 28, 2026 at 2:10 am

    The first case behaves like To<MyService>() except that you explicitly select the constructor. This means the context is passed through MyService and you can use conditions for IFoo and IBar or one of their dpependencies where in the second case you get a new context for IFoo and IBar and you will not know that they are injected into MyService.

    e.g.

    Bind<IFoo>().To<FooA>().WhenInjectedInto<MyService>();
    Bind<IFoo>().To<FooB>().WhenInjectedInto<MyOtherService>();
    

    will not work in the second case.

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

Sidebar

Related Questions

In Castle Windsor there is a feature called forwarded types where you can have
I see there is an extension for Ninject integration with asp.net-mvc but it looks
Ninject looks great, so I'd like to use it in my project. Unfortunately I
I am new to ninject, I am wondering how I can run custom initizlisation
Is there a way to use Property Injection in Ninject 2 without using the
Is anyone out there using the Prism framework with Ninject instead of Unity? I
How to use Ninject with a sample code for interface and its implementation like
I have a base class that has a repository injected into the constructor, now
In a project I'm working on there are two custom ActionFilterAttribute classes which are
I am using Ninject for DI. I have Ninject Modules that bind some services

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.