我已經(jīng)有兩個(gè)完整的類(EF域模型),并帶有相關(guān)的引用(一對(duì)多):public class Foo : IFoo{ public virtual ICollection<Bar> Bars { get; set; }}public class Bar : IBar{ public virtual Foo Foo { get; set; }}我需要通過接口使用它們才能實(shí)現(xiàn)DI。這樣的接口實(shí)現(xiàn)顯然不起作用:public interface IFoo{ ICollection<IBar> Bars { get; set; }}public interface IBar{ IFoo Foo { get; set; }}您能否請(qǐng)您以正確的方式提出建議?
1 回答

素胚勾勒不出你
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可以使接口通用:
public class Foo : IFoo<Bar>
{
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar : IBar<Foo>
{
public virtual Foo Foo { get; set; }
}
public interface IFoo<T>
{
ICollection<T> Bars { get; set; }
}
public interface IBar<T>
{
T Foo { get; set; }
}
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)
0/150
提交
取消