我正在尝试将我的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有效
我不明白我做错了什么。此外,如果您需要存储库中的更多代码,请告诉我。
我非常感谢答案!
您正在注册接口作为IrepoAuctionInterface
的实现。 .AddScoped()方法的签名如下:
public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services)
where TService : class
where TImplementation : class, TService;
这意味着TService
应该实现TImplementation
,你反过来做了。
你应该像这样翻转参数:
services.AddScoped<IrepoAuctionInterface, AuctioniRepository>();