我试图将我的代码从运行在.NET Framework 4.6.1上的Webjobs项目迁移到新的.NET Core 2.0控制台项目。我得到错误的一些错误的位置:在.NET Core控制台中使用Ninject应用
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)
};
}
}
我也越来越在我BrmJobActivator代码中的错误:
public class BrmJobActivator : IJobActivator
{
private readonly IKernel _container;
public BrmJobActivator(IKernel container)
{
_container = container;
}
public T CreateInstance<T>()
{
return _container.Get<T>();
}
}
UPDATE: 这是下的NuGet包在我的项目在安装后的警告信息Ninject包3.2.2:
谢谢你的回应。我安装了版本3.2.2,它似乎工作正常。不过,我在NuGet包中看到一条警告。我拍了一个屏幕截图,并用它更新了原始文章。该消息警告说这个软件包可能与我的项目不完全兼容。 – Sam
只是为了进一步阐明:项目的构建没有错误,我不知道以前遇到的错误。 – Sam
您可以忽略它或修改代码以使用最新版本的NInject。你需要实现一个Ninject.Modules.NinjectModule。以下链接供您参考。 https://github.com/ninject/Ninject/wiki/Modules-and-the-Kernel – Amor