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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:11:48+00:00 2026-06-14T22:11:48+00:00

I have the following class which I’m using to do a specific query on

  • 0

I have the following class which I’m using to do a specific query on the database and creating a presentation model of data to pass back to the client browser.

public class SpecificFooQuery: IPresentationQuery<FooRequest, FooResult>
{
    public SpecificFooQuery(ILogger logger, DbContext context)
    {
        this.logger = logger;
        this.context = context;
    }

    public FooResult Get(FooRequest request)
    {
        return new FooResult { ... };
    }
}

It implements the following generic interface

public interface IPresentationQuery<TRequest, TResult>
    where TRequest : class
    where TResult : class
{
    TResult Get(TRequest request);
}

But I’m having problems writing a ninject instantiation which will create my object for me. This doesn’t work but I’ve not really got any further than this so far.

kernel.Bind<IPresentationQuery<FooResult, FooRequest>>().To<SpecificFooQuery>();

Can anyone help me out with this, I’m not really sure where I’m going wrong or what I need to do to make this work.


Error   1   
The type 'SpecificFooQuery' cannot be used as type parameter 
'TImplementation' in the generic type or method   
'Ninject.Syntax.IBindingToSyntax<T1>.To<TImplementation>()'. 
There is no implicit reference conversion from 
'SpecificFooQuery' to 'IPresentationQuery<FooResult,FooRequest>'.   
  • 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-14T22:11:49+00:00Added an answer on June 14, 2026 at 10:11 pm

    I know this question is about Ninject, but if you’re doing this kind of generic trickery, you might want to try Simple Injector. It allows you to register all IPresentationQuery<TRequest, TResult> implementations in one single line of code like this:

    container.RegisterManyForOpenGeneric(
        typeof(IPresentationQuery<,>),
        typeof(IPresentationQuery<,>).Assembly);
    

    RegisterManyForOpenGeneric is an extension method on the SimpleInjector.Extensions project which can be downloaded from NuGet just as Simple Injector is.

    And wrapping all those implementations with a generic decorator would also be a one-liner:

    container.RegisterDecorator(
        typeof(IPresentationQuery<,>),
        typeof(ValidationPresentationQueryDecorator<,>));
    

    Nice about Simple Injector is that it is blazingly fast, even when dealing with generic decorators. And Simple Injector even respects your generic type constraints. You add a generic type constraint to a decorator to prevent it from being wrapped to certain types. And if that’s not possible, you can also register a conditional decorator like this:

    container.RegisterDecorator(
        typeof(IPresentationQuery<,>),
        typeof(ValidationPresentationQueryDecorator<,>),
        context => NeedsValidation(context.ImplementationType));
    

    Even this registration is optimized and the supplied predicate will only be called once per closed generic type. The RegisterDecorator method is part of the same Extensions project as RegisterManyForOpenGeneric is.

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

Sidebar

Related Questions

I have the following javascript class which I am trying to pass to an
I have a class which loads an xml file using the following: Path.Combine( AppDomain.CurrentDomain.BaseDirectory,
I have following situation - Have a MongoService class, which reads host, port, database
I have the following classes: Class called House (which have data regarding the house
I have the following class which recurs on itself to form a tree-like data
I have the following class which I am using to read in large amounts
I have the following class which handles my user logged in / logged out
I have the following asynctask class which is not inside the activity. In the
In Java I have created the following class which extends ImageView to create a
I have the following tricky problem: I have implemented a (rather complicated) class which

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.