I would like to allow for declarative mixin management in my codebase. I would like to declare an interface like
public interface IMyRepo : IRepository, ICanFindPeopleByName, ICantSing {}
So my classes can consume only the bits of the data access layer they need. In my IoC container I would like to aggregate the implementations of these interfaces into a single instance. However when I do things similar to the referenced threads, the generator throws an exception stating that interfaces are implemented in multiple places. What can I do, other than implementing my own interceptor and passing through?
Relevant Threads:
- http://stackoverflow.com/questions/2656663/help-migrating-mixins-from-castle-dynamicproxy-to-dynamicproxy2/2657506#2657506.
- http://stackoverflow.com/questions/678131/windsor-mixin-is-a-singleton
Better Example (wall of code)
public interface IIceCream {
void Eat();
}
public class IceCream : IIceCream {
public void Eat() { Console.WriteLine("Yummy!"); }
}
public interface ICake {
void NomNom();
}
public class Cake : ICake {
public void NomNom() { Console.WriteLine("Cakey!"); }
}
public interface ISprinkles {
void Oogle();
}
public class Sprinkles : ISprinkles {
public void Oogle(){ Console.WriteLine("Its Pretty!");}
}
public interface IIceCreamWithCakeAndSprinkles : IIceCream, ICake, ISprinkles {}
public class Program
{
public static void Main()
{
var gen = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new IceCream());
options.AddMixinInstance(new Cake());
options.AddMixinInstance(new Sprinkles());
var result =
gen.CreateClassProxy(typeof (object), new[] {typeof (IIceCreamWithCakeAndSprinkles)}, options) as IIceCreamWithCakeAndSprinkles;
}
}
throws
InvalidMixinConfigurationException: "The mixin IceCream adds the interface 'ConsoleApplication1.IIceCream' to the generated proxy, but the interface already exists in the proxy's additional interfaces. A mixin cannot add an interface already implemented in another way."