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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:07:25+00:00 2026-06-14T07:07:25+00:00

I am developing an application and using Ninject for DI. I would like to

  • 0

I am developing an application and using Ninject for DI. I would like to be able to inject a different object into a given method depending on the solution configuration I am using. Namely, in a “mock” configuration mode I would like to inject a mock object and in the debug/release configurations I would like to inject a real object.

Having read Ninject and configuration I understand that XML configs offer such a possiblity. However, I would like to do this without the XML if possible. (I tend to agree with Ninject that injection details shouldn’t be configurable in the published product…) I am also aware that I could use preprocessor directives to do this. What I would like to know is if this capability exists in Ninject, or if I need extensions/workarounds to accomplish it.

  • 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-14T07:07:27+00:00Added an answer on June 14, 2026 at 7:07 am

    What about preprocessor directives in your ninject configuration. It should do what you want.

    #if DEBUG
            kernel.Bind<IMyService>().To<MyServiceMock>();
    #else
            kernel.Bind<IMyService>().To<MyService>();
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing an application using Symfony 2 and would like my routes to
Been developing an application using PHP's PEAR framework, but ran into an issue where
I'm developing WinForms application using VS2010. I have about 15 projects in the solution.
I am developing Desktop application using c#.net and MySql. Is there any solution to
I am developing an application using Asp.Net.My question is whether there is any solution
I'm developing android application using HTML5, jQuery and Phonegap. But i'm not able to
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
While developing an application using gwt in ecliplse crashed. Now the server is running
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am developing an application using opencv as my college project, it's almost done

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.