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

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

通用擴(kuò)展 - 服務(wù)不實(shí)現(xiàn)接口成員

通用擴(kuò)展 - 服務(wù)不實(shí)現(xiàn)接口成員

C#
精慕HU 2022-12-24 10:41:14
有人可以幫我弄清楚我哪里出錯(cuò)了。我正在嘗試為 .Net Core 中的服務(wù)實(shí)現(xiàn)通用擴(kuò)展方法。這是我的界面 -public interface IContactService : IAddable<Contact>{    Task<List<Contact>> GetAll();}我的模型 -public partial class Contact : IBaseEntity{    public int Id { get; set; }    public string Name { get; set; }    public string Email { get; set; }    public string Phone { get; set; }}以及模型的界面 -public interface IBaseEntity { }然后我有我的通用擴(kuò)展 -public interface IAddable<T>{    AppContext Context { get; }}public static class IAddableExentions{    public static async Task<T> Add<T>(this IAddable<T> addable, T entity) where T : class, IBaseEntity    {        await addable.Context.Set<T>().AddAsync(entity);        await addable.Context.SaveChangesAsync();        return entity;    }}我的服務(wù) -public class ContactService : IContactService{    public AppContext Context;    public ContactService(AppContext context)    {        Context = context;    }    public async Task<List<Contact>> GetAll()    {        var contacts = await Context            .Contacts            .ToListAsync();        return contacts;    }}現(xiàn)在編譯器抱怨說(shuō) -“ContactService”未實(shí)現(xiàn)接口成員“IAddable.Context”當(dāng)我嘗試打電話時(shí),service.Add(contact)我得到 -IContactService 不包含 Add 的定義,并且找不到接受 IContactService 類(lèi)型的第一個(gè)參數(shù)的可訪問(wèn)擴(kuò)展方法。我已經(jīng)在另一個(gè)項(xiàng)目中使用了它,但是對(duì)于我的一生,我無(wú)法弄清楚為什么它在這里不起作用......
查看完整描述

1 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

您聲明Context為ContactService,


public class ContactService : IContactService

{

    public AppContext Context; //<-- field


//...

但是IAddable<T>界面


public interface IAddable<T>

{

    AppContext Context { get; }

}

of which IContactServiceis derived from, 指示它 ( Context) 應(yīng)該是一個(gè)屬性:


public class ContactService : IContactService

{

    public AppContext Context { get; }


//...


查看完整回答
反對(duì) 回復(fù) 2022-12-24
  • 1 回答
  • 0 關(guān)注
  • 115 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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