我試圖將我的代碼從運行在.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