2017-01-15 10 views
3

ASP.NET Coreプロジェクトをバージョン1.1にアップデートしましたが、以来、次のエラーが表示されています(最初の呼び出しでは正常に動作しますが、以下では失敗します)2番目の呼び出しでLoggingFactoryが処理されました

廃棄オブジェクトにアクセスできません。次の行に

private ILogger logger; 
    public ValuesController(ILoggerFactory loggingFactory) 
    { 
     logger = loggingFactory.CreateLogger<ValuesController>(); 
    } 

プロジェクトはコンテナとしてDryIocを使用していると、私の起動は次のようになります。

using System; 
using DryIoc; 
using Microsoft.AspNetCore.Builder; 
using Microsoft.AspNetCore.Hosting; 
using Microsoft.Extensions.Configuration; 
using Microsoft.Extensions.DependencyInjection; 
using Microsoft.Extensions.Logging; 
using DryIoc.Microsoft.DependencyInjection; 

namespace WebApplication2 
{ 
    public class CompositionRoot 
    { 
     public CompositionRoot(IRegistrator r){} 
    } 

    public class Startup 
    { 
     public Startup(IHostingEnvironment env) 
     { 
      var builder = new ConfigurationBuilder() 
       .SetBasePath(env.ContentRootPath) 
       .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
       .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
       .AddEnvironmentVariables(); 
      Configuration = builder.Build(); 
     } 

     public IConfigurationRoot Configuration { get; } 

     // This method gets called by the runtime. Use this method to add services to the container. 
     public IServiceProvider ConfigureServices(IServiceCollection services) 
     { 
      // Add framework services. 
      services.AddMvc().AddControllersAsServices(); 
      return new Container() 
      // setup DI adapter 
      .WithDependencyInjectionAdapter(services, 
       // optional: propagate exception if specified types are not resolved, and prevent fallback to default Asp resolution 
       throwIfUnresolved: type => type.Name.EndsWith("Controller")) 
      // add registrations from CompositionRoot classs 
      .ConfigureServiceProvider<CompositionRoot>(); 
     } 

     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
     { 
      loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
      loggerFactory.AddDebug(); 

      app.UseMvc(); 
     } 
    } 
} 

私project.jsonは次のようになります。

{ 
"dependencies": { 
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0", 
    "Microsoft.Extensions.Logging": "1.1.0", 
    "Microsoft.Extensions.Configuration.Json": "1.1.0", 
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0", 
    "Microsoft.AspNetCore.Mvc": "1.1.0", 
    "Microsoft.AspNetCore.Routing": "1.1.0", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0", 
    "Microsoft.Extensions.Logging.Console": "1.1.0", 
    "Microsoft.Extensions.Logging.Debug": "1.1.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", 
    "DryIoc.Microsoft.DependencyInjection": "1.0.2" 
}, 
    "tools": { 
    }, 
    "frameworks": { 
     "netcoreapp1.1": { 
      "dependencies": { 
       "Microsoft.NETCore.App": { 
        "type": "platform", 
        "version": "1.1.0" 
       } 
      } 
     } 
    }, 
    "buildOptions": { 
     "emitEntryPoint": true 
    }, 
    "runtimeOptions": { 
     "configProperties": { 
      "System.GC.Server": true 
     } 
    }, 
    "scripts": { 
     "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 

}

すべてのヘルプは大

+0

で更新されています。あなたがDisposeの動作の回りに多くの乱れがあった「DryIoc」を使用しているようです。 使用しているバージョンを確認できますか? – Stuart

+0

'project.json.lock'でバージョンを確認できます – Stuart

+0

NuGetからDryIoc.dll 2.9.7を追加しました。実行時に2.9.7をチェックすると、project.json.lockはまだ2.8 .3、project.json.lockを正しく取得する方法がわかりません... – smolesen

答えて

0

問題はv1.1.1に修正されています。

問題は外部インスタンスが一時的なものとして登録されているためでした。使い捨てのインスタンスはコンテナによって追跡されますが、最初のスコープ(要求)で破棄されるため、2番目のスコープ(要求)で例外がスローされます。今はシングルトンとして登録されています。

Btw。 DryIocコンテナで問題を見つけたり、フレームワーク登録をカスタマイズしたりするには、registerDescriptor代理人をWithDependencyInjectionAdapterメソッドに提供することができます。 DryIocレポのサンプルはexample usage

関連する問題