尝试使用addScoped ASP.Net core 2.1将Irepositories添加到服务时出错

问题描述 投票:0回答:1

我正在尝试将我的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有效

我不明白我做错了什么。此外,如果您需要存储库中的更多代码,请告诉我。

我非常感谢答案!

c# asp.net asp.net-core
1个回答
1
投票

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

public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services)
    where TService : class
    where TImplementation : class, TService;

这意味着TService应该实现TImplementation,你反过来做了。

你应该像这样翻转参数:

services.AddScoped<IrepoAuctionInterface, AuctioniRepository>();
© www.soinside.com 2019 - 2024. All rights reserved.