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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:18:29+00:00 2026-05-18T03:18:29+00:00

Suppose we have an interface ICat that is derived from ICatBase and ICatExtension as

  • 0

Suppose we have an interface ICat that is derived from ICatBase and ICatExtension as shown below. For both distinct interfaces, an implementation is available, CatBase and CatExtension. How can Castle’s DynamicProxy be used to merge these into an instance of ICat?

Is it possible to create a proxy in which ICatExtension is implemented by CatExtension and ICatBase is ‘implemented’ by an interceptor? How can this be achieved?

public interface ICatBase
{
   string Name { get; set; }
   int Age { get; set; }
}

public interface ICatExtension
{
   string Description { get; }
}

public interface ICat : ICatBase, ICatExtension
{
}

public class CatBase : ICatBase
{
   public string Name { get; set; }
   public int Age { get; set; }
}

public class CatExtension : ICatExtension
{
   public string Description
   {
      get { return "Furry"; }
   }
}

EDIT

I have been trying to use mixins to make this work, but the code below results in a NotImplementedException.

var generator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new CatBase());
options.AddMixinInstance(new CatExtension());
var cat  = generator.CreateInterfaceProxyWithoutTarget<ICat>(options);        
cat.Name = "Joey";

This is a DynamicProxy2 error: There are no interceptors specified for method ‘Void set_Name(System.String)’ which has no target. When calling method without target there is no implementation to ‘proceed’ to and it is the responsibility of the interceptor to mimic the implementation (set return value, out arguments etc)

I could create a custom interceptor that intercepts calls and dispatches to the correct interface, but I feel there must be an easier/better way. Am I correct?

EDIT #2

Thank you, Krzysztof! Using the lines below was the solution.

var generator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new CatBase());
options.AddMixinInstance(new CatExtension());

var cat = (ICat)generator.CreateClassProxyWithTarget(typeof(object), new[] { typeof(ICat)}, new object(), options);

EDIT #3

As a final step, I have configured a Windsor container to create the proxy from this example. The only way I was able to do this, was by specifying a name “Cat” and resolving an instance of System.Object by specifying the name and casting to the ICat interface afterwards.

WindsorContainer container = new WindsorContainer();
container.Register(
    Castle.MicroKernel.Registration.Component.For<object>().
        Named("Cat").
        Proxy.AdditionalInterfaces(typeof (ICat)).
        Proxy.MixIns(new CatBase()).
        Proxy.MixIns(new CatExtension())
    );

var cat = (ICat)container.Resolve(typeof(object), "Cat");

Is there a more elegant way to this in which I can just ask the container for an ICat instance, without referring to a particular name?

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

    Mixins are what you’d normally use for that.

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

Sidebar

Related Questions

Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
Suppose we have a table A: itemid mark 1 5 2 3 and table
Suppose I have the following CSS rule in my page: body { font-family: Calibri,
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have BaseClass with public methods A and B, and I create DerivedClass

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.