相关疑难解决方法(0)

非泛型方法'IServiceProvider.GetService(Type)'不能与类型参数一起使用

我正在使用.NET Core依赖注入,但是当我试图在另一个类中获取服务时,我得到'IServiceProvider.GetService(Type)'不能与类型参数一起使用'错误.

这个错误意味着什么?我知道泛型类型的参数是这样的:GenericInterface <>,而GetService方法不会将GenericInterface <>作为参数.

为什么我会收到此错误,如何解决?

界面

public interface IService
{
   void Process();
}
Run Code Online (Sandbox Code Playgroud)

实现接口的类

public class Service : BaseService<IConfig, SomType>
{
    public Service(
        ILogger logger : base(logger)
    {
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

BaseService类是一个抽象类,它实现了IService接口.

public abstract class BaseService<TConfig, TE> : AnotherBaseService, IService where TConfig : IConfig where TE : struct, IConvertible
{
      protected BaseService(ILogger logger): base(logger)
      {
      } 

      ...
}
Run Code Online (Sandbox Code Playgroud)

AnotherBaseService

public abstract class BaseService
{
   protected readonly ILogger Logger;

   protected BaseService(ILogger logger)
   {
      Logger = logger;
   }

   ...
}
Run Code Online (Sandbox Code Playgroud)

我是如何注册的. …

c# console-application .net-core dependency-inversion

11
推荐指数
2
解决办法
4423
查看次数

EF Core - 在没有源的情况下运行迁移 - 相当于EF6的migrate.exe

是否可以从包含迁移和dbcontext的DLL运行ef迁移?我想dotnet ef database update在不需要project.json和源代码的情况下运行我的构建工件.

换句话说,我正在寻找EF6 的migrate.exe https://msdn.microsoft.com/en-us/data/jj618307.aspx

.net entity-framework .net-core

8
推荐指数
2
解决办法
3673
查看次数

在.NET core 2.0中创建迁移步骤时,将"IDesignTimeDbContextFactory <ServicesDbContext>"的实现添加到项目错误中

我有一个.NET核心1.0 webapp工作正常.我不得不升级到.NET Core 2.0.我还必须为我的SQLite数据库添加一个迁移步骤.

如果我启动此命令:

添加迁移MyMigrationStepName

我收到此错误:

无法创建"ServicesDbContext"类型的对象.将"IDesignTimeDbContextFactory"的实现添加到项目中,或者参阅https://go.microsoft.com/fwlink/?linkid=851728以获取在设计时支持的其他模式.

我已经在SO和其他博客和网站上看到了很多答案,但他们实际上并没有说明在哪里实现这样的界面以及具体方法应该包含哪些代码!

.net c# .net-2.0 ef-migrations

5
推荐指数
1
解决办法
4818
查看次数