2017-08-30 154 views
0

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

回答

1

另外這裏得到一個錯誤,上面寫着:參數1:無法轉換System.Reflection.Assembly到System.Co llections.Generic.IEnumerable

Ninject的最新預發佈版本有一些變化。請改爲安裝最新的穩定版本3.2.2。

enter image description here

我測試了我的身邊你的代碼。將Ninject版本更新到3.2.2後,代碼運行良好。

+0

謝謝你的迴應。我安裝了版本3.2.2,它似乎工作正常。不過,我在NuGet包中看到一條警告。我拍了一個屏幕截圖,並用它更新了原始文章。該消息警告說這個軟件包可能與我的項目不完全兼容。 – Sam

+0

只是爲了進一步闡明:項目的構建沒有錯誤,我不知道以前遇到的錯誤。 – Sam

+0

您可以忽略它或修改代碼以使用最新版本的NInject。你需要實現一個Ninject.Modules.NinjectModule。以下鏈接供您參考。 https://github.com/ninject/Ninject/wiki/Modules-and-the-Kernel – Amor

0

Ninject 3.3.0於2017年9月26日發佈,現在的目標是.NET標準2.0,因此也運行在.NET Core 2.0上。更新到3.3.0將修復警告。

相關問題