0
私は2つの異なるコントローラを持つWebアプリケーションを持っており、コントローラへの入力として構成ファイルを使用しています。以前は、ただ1つの設定ファイルを使用していただけで、それをカーネルにバインドでき、すべてうまく動作しました。しかし、私は2つの別々の設定ファイルを使用して、どのファイルを使用するかを理解するために必要となります。ここに私が私がやると思った方法の例があります。私が1つしか持っていなかったときに、私が設定をバインドするために行ったこともコメントされました。NinjectはGlobal.asaxで同じタイプの2つの異なるパラメータをバインドします
var kernel = NinjectWebApi.Kernel;
//get base dependency instances from the container
var configurationClient = kernel.Get<IConfigurationClient>();
//initialise local dependencies
var config1 = configurationClient.Get(new GetConfigurationByKeyRequest("Config1"));
var config2 = configurationClient.Get(new GetConfigurationByKeyRequest("Config2"));
//bind local dependencies
//This is what I did when I had just one config
//kernel.Bind<IConfiguration>().ToMethod(c => config1.Configuration);
kernel.Bind<IMy1Controller>().To<My1Controller>()
.WithConstructorArgument("config1", config1.Configuration)
.WithConstructorArgument("config2", config2.Configuration);
kernel.Bind<IMy2Controller>().To<My2Controller>()
.WithConstructorArgument("config2", config2.Configuration);
//Set the dependency resolver to use ninject
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
「WithConstructorArgument」の目的は、入力を指定するために使用できない場合はどうですか?