1
我想允许在我的代码库中声明混合管理。我想声明一个接口,如如何将界面聚合到城堡动态代理
public interface IMyRepo : IRepository, ICanFindPeopleByName, ICantSing {}
所以我的类只能使用他们需要的数据访问层的位。在我的IoC容器中,我想将这些接口的实现集合到一个实例中。但是,当我执行与引用的线程类似的事情时,生成器会引发一个异常,指出接口在多个位置实现。除了实现我自己的拦截器并通过之外,我能做些什么?
相关主题:
更好的例子(代码壁)
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;
}
}
抛出
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."
什么异常确切地是你得到DP不会让你创建代理时,有歧义,也就是当你试图添加为混合多种类型实现任何特定的接口,从那时起它不知道哪个实现转发。 – 2010-08-10 23:07:52
在这种情况下,没有任何指定的mixin对象实现相同的接口。这似乎是一个问题,声明'输出'接口是mixin接口上的聚合。 (请参阅更新的问题) – JeffreyABecker 2010-08-11 14:40:09