第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

C#交叉依賴接口問題

C#交叉依賴接口問題

C#
收到一只叮咚 2021-05-18 17:13:48
我已經(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; }

}


查看完整回答
反對(duì) 回復(fù) 2021-05-21
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)