コードベースで宣言型 mixin 管理を許可したいと考えています。次のようなインターフェイスを宣言したい
public interface IMyRepo : IRepository, ICanFindPeopleByName, ICantSing {}
したがって、私のクラスは、必要なデータ アクセス レイヤーのビットのみを使用できます。私の IoC コンテナーでは、これらのインターフェイスの実装を 1 つのインスタンスに集約したいと考えています。ただし、参照されたスレッドと同様のことを行うと、ジェネレーターは、インターフェイスが複数の場所で実装されていることを示す例外をスローします。独自のインターセプターを実装して通過する以外に何ができますか?
関連するスレッド:
より良い例 (コードの壁)
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."