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