为了账号安全,请及时绑定邮箱和手机立即绑定

尝试使用 addScoped ASP.Net core 2.1 将 Irepositories

尝试使用 addScoped ASP.Net core 2.1 将 Irepositories

C#
qq_笑_17 2022-01-15 19:33:41
我正在尝试将我的 Irepository 接口和 irepository 添加到服务中,以便我可以使用它们。我这样做:services.AddScoped<AuctioniRepository, IrepoAuctionInterface>();这是我得到的错误:错误 CS0311 类型“NackowskiLillMygel.Data.IrepoAuctionInterface”不能用作泛型类型或方法“ServiceCollectionServiceExtensions.AddScoped(IServiceCollection)”中的类型参数“TImplementation”。没有从“NackowskiLillMygel.Data.IrepoAuctionInterface”到“NackowskiLillMygel.Data.AuctioniRepository”的隐式引用转换。NackowskiLillMygel 源\repos\NackowskiLillMygel\NackowskiLillMygel\Startup.cs 39 活动我不明白我做错了什么。另外,如果您需要来自存储库的更多代码,请告诉我。我非常感谢您的回答!
查看完整描述

2 回答

?
沧海一幻觉

TA贡献1824条经验 获得超5个赞


您正在将接口注册为IrepoAuctionInterface. .AddScoped() 方法的签名如下:


public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services)

    where TService : class

    where TImplementation : class, TService;

这意味着TService应该实现TImplementation,而您则以相反的方式进行。


你应该像这样翻转参数:


services.AddScoped<IrepoAuctionInterface, AuctioniRepository>();


查看完整回答
反对 回复 2022-01-15
?
繁花不似锦

TA贡献1851条经验 获得超4个赞

只需IrepoAuctionInterface在类中实现接口AuctioniRepository

喜欢

public class AuctioniRepository : IrepoAuctionInterface
{
}


查看完整回答
反对 回复 2022-01-15
  • 2 回答
  • 0 关注
  • 213 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号