我正在尝试将我的 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>();
繁花不似锦
TA贡献1851条经验 获得超4个赞
只需IrepoAuctionInterface在类中实现接口AuctioniRepository
喜欢
public class AuctioniRepository : IrepoAuctionInterface
{
}- 2 回答
- 0 关注
- 213 浏览
添加回答
举报
0/150
提交
取消
