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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:52:21+00:00 2026-05-22T21:52:21+00:00

I have this class hierarchy: public interface ISR { } public interface ICU {

  • 0

I have this class hierarchy:

public interface ISR { }
public interface ICU { }
public interface IFI { }   

public class CU : ICU { }

public class SR : ISR
{
    public SR(IFI fi)
    {
        FI = fi;
    }

    public IFI FI { get; set; }
}

public class FI : IFI
{
    public FI(ISR sr, ICU cu)
    {
        SR = sr;
        CU = cu;
    }

    public ISR SR { get; set; }
    public ICU CU { get; set; }
}

public class Module : NinjectModule
{
    public override void Load()
    {
        Bind<ISR>().To<SR>();
        Bind<ICU>().To<CU>();
        Bind<IFI>().To<FI>();
    }
}

class Program
{
    static void Main(string[] args)
    {
        var kernel = new StandardKernel(new Module());

        var sr = kernel.Get<ISR>();
    }
}

When I run this code, I have an exception because I have a cyclic dependency. The SR class needs an instance of IFI to be injected in order to be completed, and the FI class needs an instance of ISR to be injected.

Of course, using a property injection doesn’t solve this issue.

I have a particularity though: I need ISR to be constructed first, and it is this instance which must be given to FI. So ISR and IFI need to share a scope.

How would you solve that with Ninject?

  • 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-22T21:52:22+00:00Added an answer on May 22, 2026 at 9:52 pm

    The best way to handle this problem is to refactor your design to remove the cyclic dependency. Almost all cyclic dependencies can be removed with a proper design. If you have cyclic dependencies there is usually a design flaw. Most likely you do not fulfill the Single Responsibility Principle.

    Otherwise you have to do two way property injection and ensure they have the same scope. E.g. InCallScope from the NamedScope extension. See http://www.planetgeek.ch/2010/12/08/how-to-use-the-additional-ninject-scopes-of-namedscope/

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

Sidebar

Related Questions

I have this class. public class Foo { public Guid Id { get; set;
I have a hierarchy that looks something like this: class Base { public: void
I have a class hierarchy, this one: type TMatrix = class protected //... public
I have this class called Table: class Table { public string Name { get
I have this class/interface definitions in C# public class FooBase { ... protected bool
I have a class hierarchy like this: @Entity @Table (name=call_distribution_policies) @Inheritance (strategy=InheritanceType.JOINED) public class
Here's the deal. I have a big class hierarchy and I have this one
This is probably not possible, but I have this class: public class Metadata<DataType> where
I have the following class hierarchy: public class Row : ICloneable, IComparable, IEquatable<Row>, IStringIndexable,
Suppose I have a small inheritance hierarchy of Animals: public interface IAnimal { string

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.