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

  • Home
  • SEARCH
  • 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 5965325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:35:26+00:00 2026-05-22T19:35:26+00:00

I have an open generic interface, which i implement with a non generic class,

  • 0

I have an open generic interface, which i implement with a non generic class, and i want to inject this class using castle windsor, but am struggling…..

Lets say i have the following interface

public interface IMyInterface<T>
{
    bool DoSomething(T param);
}

And then i have the following class that implements this interface like so

public class MyClass : IMyInterface<string>
{
    public bool DoSomething(string param)
    {
        // Do Something
        return true;
    }
}

I want to be able to resolve the interface using castle like this, so that the injectedObject becomes an instance of MyClass.

WindsorContainer container = new WindsorContainer(new XmlInterpreter(newConfigResource("castle")));
IMyInterface<string> injectedObject = container.Resolve<IMyInterface<string>>();

Is this possible, or have i gone off track slightly? If its possible, how do i set up the castle config section? I have tried using the ‘1 notation to indicate that the interface is an open generic type, but you get an error if the implementation is not also generic, which in this case it is not.

Any help appreciated

  • 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-22T19:35:27+00:00Added an answer on May 22, 2026 at 7:35 pm

    We use the fluent interface in my team so it’s been a while since I’ve looked at the config file syntax. The basic principle is this: your service is IMyInterface<string> and the implementing type is MyClass. So I think it would be something like this:

    <component service="Namespace.IMyInterface`1[[System.String, mscorlib]], AssemblyName"
            type="Namespace.MyClass, AssemblyName" />
    

    You say you get an error. What is the error? I guess it is because you have defined the service as IMyInterface<> without supplying the type parameter. If you want to do that, as your question implies, the implementing type must also be generic:

    <component service="Namespace.IMyInterface`1, AssemblyName"
            type="Namespace.MyGenericClass`1, AssemblyName" />
    

    Note that you can register both components. If you do that, resolving IMyInterface<string> will get you an instance of MyClass, while resolving IMyInterface<AnyOtherType> will get you an instance of MyGenericClass<AnyOtherType>.

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

Sidebar

Related Questions

I have a website for which I need to implement the admin interface. The
i have a input tag which is non editable, but some times i need
I'm trying to create an open instance delegate for a generic interface method, but
When we have something like this: interface ISomething<U,V> { ... } class Something<U,V> :
In php I have open a .php file and want to evaluate certain lines.
One problem I have with open-source is not often the product or documentation, but
I'm using c#, and have an open tcpip connection receiving data. Is it possible
This question is kind of the next level of F# Set using custom class
So I've wired up my open generic plugin in StructureMap like so scan.ConnectImplementationsToTypesClosing(typeof(IRepository<>)); But
I am trying to use Generic DataContract class so that I don't have to

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.