2

LifetimeScope 次のように作成されたときに登録を追加できることを私は知っています:

using(var scope = container.BeginLifetimeScope(builder =>  
    {  builder.RegisterType<Override>().As<IService>();
       builder.RegisterModule<MyModule>();
    }))
{
  // The additional registrations will be available
  // only in this lifetime scope.
}

作成後に登録を追加することLifetimeScopeはできますか? using(たとえば、ブロック内に登録を追加するため)

4

1 に答える 1

0

ComponentRegistryのプロパティにアクセスできます。ILifetimeScopeこのオブジェクトを使用すると、静的メソッドIComponentRegistrationを使用して作成できる新規登録できます。RegistrationBuilder

using(var scope = container.BeginLifetimeScope())
{
    var registration = RegistrationBuilder.ForType<ServiceA>()
                                          .As<IService>()
                                          .CreateRegistration();
    scope.ComponentRegistry.Register(registration); 

    scope.Resolve<IService>(); 
}
于 2016-08-10T19:18:30.697 に答える