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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:33+00:00 2026-05-23T03:12:33+00:00

I have a problem with Ninject trying to resolve an interface type where the

  • 0

I have a problem with Ninject trying to resolve an interface type where the concrete type derives from an abstract base class that implements the interface.

EDIT: This is on Windows Mobile using .NET CF.

My particular issue involves presenters and views, so I stick to that in this example instead of foos and bars.

I want to inject factories for presenters and views to allow for late creation of those instances deep down the UI view stack.

Below I’ve omitted all error checking for better readability.

My factory interface:

public interface IFactory<T>
{
    T Create();
}

My presenter and view:

public sealed class Presenter
{
    private readonly View view;

    public Presenter(View view)
    {
        this.view = view;
    }
}

public sealed class View
{
    public View()
    {
    }
}

First, I’ll show what works perfectly, that Ninject resolves as expected. This will not include the abstract base class I mentioned at the beginning. After this, I’ll add the slight modifications with the abstract base class that will make Ninject throw when trying to resolve the dependencies.

We see above that the presenter depends on the view, so the presenter factory will depend on the view factory:

public sealed class GoodPresenterFactory : IFactory<Presenter>
{
    private readonly IFactory<View> viewFactory;

    public GoodPresenterFactory(IFactory<View> viewFactory)
    {
        this.viewFactory = viewFactory;
    }

    public Presenter Create()
    {
        return new Presenter(this.viewFactory.Create());
    }
}

public sealed class ViewFactory : IFactory<View>
{
    public ViewFactory()
    {
    }

    public View Create()
    {
        return new View();
    }
}

Wiring this up with Ninject:

Bind<IFactory<Presenter>>().To<GoodPresenterFactory>();
Bind<IFactory<View>>().To<ViewFactory>();

And then resolving the presenter factory:

var presenterFactory = container.Get<IFactory<Presenter>>();

Everything up until now works perfectly. The dependency on the view factory inside the presenter factory is resolved as expected.

Now, I have a million classes that looks like GoodPresenterFactory above and I therefore wanted a small base class to handle some trivial common stuff, like the dependency on the view factory in the presenter factory:

public abstract class FactoryBase<T, U> : IFactory<T>
{
    protected readonly U dependency;

    protected FactoryBase(U dependency)
    {
        this.dependency = dependency;
    }

    public abstract T Create();
}

Then the presenter factory will change and something in that change will make Ninject fail resolving:

public sealed class BadPresenterFactory : FactoryBase<Presenter, IFactory<View>>
{
    public BadPresenterFactory(IFactory<View> viewFactory)
        : base(viewFactory)
    {
    }

    public override Presenter Create()
    {
        return new Presenter(this.dependency.Create());
    }
}

And changing the Ninject wiring accordingly:

Bind<IFactory<Presenter>>().To<BadPresenterFactory>();
Bind<IFactory<View>>().To<ViewFactory>();

Those changes will make Ninject throw an ArgumentNullException when doing

var presenterFactory = container.Get<IFactory<Presenter>>();

Call stack from the exception:

at System.Reflection.RuntimeMethodInfo.GetParentDefinition()
at System.Reflection.CustomAttribute.IsDefined(MemberInfo member, Type caType, Boolean inherit)
at System.Reflection.RuntimeMethodInfo.IsDefined(Type attributeType, Boolean inherit)
at System.Attribute.IsDefined(MemberInfo element, Type attributeType, Boolean inherit)
at System.Attribute.IsDefined(MemberInfo element, Type attributeType)
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute(MemberInfo member, Type type)
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo member)
at Ninject.Selection.Selector.<>c__DisplayClassa.<SelectMethodsForInjection>b__9(IInjectionHeuristic h)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Ninject.Selection.Selector.<SelectMethodsForInjection>b__8(MethodInfo m)
at System.Linq.Enumerable.<WhereIterator>d__0`1.MoveNext()
at Ninject.Planning.Strategies.MethodReflectionStrategy.Execute(IPlan plan)
at Ninject.Planning.Planner.<>c__DisplayClass2.<GetPlan>b__0(IPlanningStrategy s)
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable`1 series, Action`1 action)
at Ninject.Planning.Planner.GetPlan(Type type)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
at Ninject.Activation.Context.Resolve()
at Ninject.KernelBase.<Resolve>b__4(IContext context)
at System.Linq.Enumerable.<SelectIterator>d__d`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__b0`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
at NinjectTest.Program.Main()

If I modify FactoryBase so that it has no dependency, it’s just a naked base class, then Ninject also fails.

public abstract class NakedFactoryBase<T> : IFactory<T>
{
    protected NakedFactoryBase()
    {
    }

    public abstract T Create();
}

public sealed class PointlessPresenterFactory : NakedFactoryBase<Presenter>
{
    private readonly IFactory<View> viewFactory;

    public PointlessPresenterFactory(IFactory<View> viewFactory)
    {
        this.viewFactory = viewFactory;
    }

    public override Presenter Create()
    {
        return new Presenter(this.viewFactory.Create());
    }
}

As you can see, that failing PointlessPresenterFactory is identical to the succeeding GoodPresenterFactory, apart from the direct IFactory<Presenter> implementation in GoodPresenterFactory, as opposed to the completeley naked base class used in PointlessPresenterFactory.

Any idea why Ninject fails to resolve when the factory base class is used?

  • 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-23T03:12:34+00:00Added an answer on May 23, 2026 at 3:12 am

    This issue has been fixed in build 2.3.0.46 and will be part of the next release (2.4).

    NOTE: because CF seems not to allow to detect is a method is generic or not the Inject attribute can not be defined on base methods anymore. It has to be defined on the overload method.

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

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular
I have a problem with a little .Net web application which uses the Amazon
I have a problem in my project with the .designer which as everyone know

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.