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

The Archive Base Latest Questions

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

In Castle Windsor there is a feature called forwarded types where you can have

  • 0

In Castle Windsor there is a feature called forwarded types where you can have one component configuration for multiple services. For example:

var container = new WindsorContainer();
container.Register(
   Component.For<Bar>().Forward<IFoo>()
      .ImplementedBy<FooBar>());
var foo = container.Resolve<IFoo>();
var bar = container.Resolve<Bar>();
Debug.Assert(foo == bar);

(this Debug.Assert works ’cause Windsor by default registers things as singletons)

How to achieve this in Ninject (version 2) ?

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

    I’m interested to see if anyone else chimes in with a better solution, but here’s an option:

    Use a special IProvider when binding to do the forward:

    public class ForwardProvider<ForwardType> : Ninject.Activation.IProvider
    {
        #region IProvider Members
        public object Create( IContext context )
        {
            return context.Kernel.Get<ForwardType>();
        }
    
        public Type Type
        {
            get { return typeof( ForwardType ); }
        }
        #endregion
    }
    

    and then when binding:

    IKernel kernel = new StandardKernel();
    kernel.Bind<ITestAdapter>().To<TestAdapter>().InSingletonScope();
    kernel.Bind<IAnotherAdapter>().ToProvider<ForwardProvider<ITestAdapter>>();
    

    and my test:

    var foo = kernel.Get<ITestAdapter>();
    foo.Indicator = 5;
    
    var bar = kernel.Get<TestAdapter>();
    Assert.That( foo.Indicator, Is.EqualTo( 5 ) );
    
    var baz = kernel.Get<IAnotherAdapter>();
    Assert.That( baz.Indicator, Is.EqualTo( 5 ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a method for Castle Windsor to inject multiple concrete implementations of a
How does Castle Windsor determine which constructor to resolve when there are multiple constructors
Using Castle Windsor, I have a component configured with the transient lifestyle: <component id=publish.mapping.default
Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties
Possible Duplicate: Where can I download the Castle Windsor WcfIntegration Facilities dll? I need
I've been using Castle Windsor in my previous project and I liked it a
I'm using Castle Windsor to do some dependency injection, specifically I've abstracted the DAL
I'm using castle windsor for a pet-project I'm working on. I'm starting to notice
Does anyone know if there are new binaries for the castle logging facility using
I'm using Castle Windsor, and I've got the following: public class NhibernateRepository<T> : IRepository<T>

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.