.net core 在.NET核心控制台应用程序中使用Ninject

.net core 在.NET核心控制台应用程序中使用Ninject,.net-core,ninject,azure-webjobs,.net-core-2.0,.net Core,Ninject,Azure Webjobs,.net Core 2.0,我正在尝试将代码从运行在.NETFramework 4.6.1上的Webjobs项目迁移到新的.NETCore2.0控制台项目。我在这里遇到了一些错误: class Program { // Here I'm getting IKernel is obsolete. Use IKernelConfiguration and IReadOnlyKernel message. // Also a message that reads: StandardKerynel is obsolet

我正在尝试将代码从运行在.NETFramework 4.6.1上的Webjobs项目迁移到新的.NETCore2.0控制台项目。我在这里遇到了一些错误:

class Program
{
   // Here I'm getting IKernel is obsolete. Use IKernelConfiguration and IReadOnlyKernel message.
   // Also a message that reads: StandardKerynel is obsolete. Use StandardKernelConfiguration and StandardReadOnlyKernel 
   static readonly IKernel Kernel = new StandardKernel();
   static JobHostConfiguration config;

   static void Main(string[] args)
   {
      Environment.SetEnvironmentVariable("AzureWebJobsDashboard", "connection");
      Environment.SetEnvironmentVariable("AzureWebJobsStorage", "storage connection");

      BootStrapIoc();

      config = new JobHostConfiguration();

      if (config.IsDevelopment)
      {
          config.UseDevelopmentSettings();
      }

      var host = new JobHost(config);
      host.RunAndBlock();
   }

   private static void BootStrapIoc()
   {
      // Also getting an error here that reads: Argument 1: Cannot convert System.Reflection.Assembly to System.Collections.Generic.IEnumerable<Ninject.Modules.NinjectModule>
      Kernel.Load(Assembly.GetExecutingAssembly());
      config = new JobHostConfiguration
      {
         JobActivator = new BrmJobActivator(Kernel)
      };
   }
}
类程序
{
//在这里,我发现IKernel已过时。请使用IKernelConfiguration和IReadOnlyKernel消息。
//还有一条消息显示:StandardKerynel已过时。请使用StandardKernelConfiguration和StandardReadOnlyKernel
静态只读IKernel Kernel=new-StandardKernel();
静态JobHostConfiguration配置;
静态void Main(字符串[]参数)
{
SetEnvironmentVariable(“AzureWebJobsDashboard”、“connection”);
setEnvironment变量(“AzureWebJobsStorage”、“存储连接”);
BootStrapIoc();
config=newjobhostconfiguration();
if(config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host=新作业主机(配置);
host.RunAndBlock();
}
私有静态void BootStrapIoc()
{
//此处还获取一个错误,该错误为:参数1:无法将System.Reflection.Assembly转换为System.Collections.Generic.IEnumerable
Load(Assembly.getExecutionGassembly());
config=newjobhostconfiguration
{
JobActivator=新的BrmJobActivator(内核)
};
}
}
我的BrmJobActivator代码中也有错误:

public class BrmJobActivator : IJobActivator
{
   private readonly IKernel _container;

   public BrmJobActivator(IKernel container)
   {
       _container = container;
   }

   public T CreateInstance<T>()
   {
       return _container.Get<T>();
   }
}
公共类BrmJobActivator:IJobActivator
{
专用只读IKernel_容器;
公共BRMJOBOActivator(IKernel容器)
{
_容器=容器;
}
公共创建实例()
{
return_container.Get();
}
}
更新: 这是安装Ninject软件包3.2.2后,我的项目中NuGet软件包下的警告消息:

此处还获取一个错误,该错误为:参数1:无法将System.Reflection.Assembly转换为System.Collections.Generic.IEnumerable

Ninject的最新预发布版本中有一些更改。请改为安装最新的stable 3.2.2版本

我在我这边测试了你的代码。将Ninject版本更新为3.2.2后,代码运行良好

此处还获取一个错误,该错误为:参数1:无法将System.Reflection.Assembly转换为System.Collections.Generic.IEnumerable

Ninject的最新预发布版本中有一些更改。请改为安装最新的stable 3.2.2版本


我在我这边测试了你的代码。将Ninject版本更新为3.2.2后,代码运行良好。

于2017年9月26日发布,现在面向.NET标准2.0,因此也运行在.NET Core 2.0上。更新到3.3.0将修复此警告。

于2017年9月26日发布,现在的目标是.NET Standard 2.0,因此也运行在.NET Core 2.0上。更新到3.3.0将修复警告。

感谢您的回复。我安装了3.2.2版,它似乎工作正常。但是,我在NuGet软件包下看到一个警告。我拍了一张屏幕截图,并用它更新了原来的帖子。该消息警告此程序包可能与我的项目不完全兼容。请进一步澄清:项目生成时没有错误,我不知道以前遇到的错误。您可以忽略它或修改代码以使用最新版本的NInject。您需要实现Ninject.Modules.NinjectModule。下面的链接供您参考。谢谢你的回复。我安装了3.2.2版,它似乎工作正常。但是,我在NuGet软件包下看到一个警告。我拍了一张屏幕截图,并用它更新了原来的帖子。该消息警告此程序包可能与我的项目不完全兼容。请进一步澄清:项目生成时没有错误,我不知道以前遇到的错误。您可以忽略它或修改代码以使用最新版本的NInject。您需要实现Ninject.Modules.NinjectModule。下面的链接供您参考。