Having trouble getting the value of a ConstructorArgument parameter passed to kernel.Get(). I want to use the parameter\'s value to determine which of two string values will
I needed to use ToMethod()
to get access to the appropriate context.
Bind().ToMethod(
ctx => {
var idNum = ctx.Parameters.First(p => p.Name == "idNum")
.GetValue(ctx, null) as string
;
if (idNum == 2) {
return new DBProviderB(new EF_DBEntities(
ConfigurationManager.ConnectionStrings["EF_DB_b_conn1"]
.ToString()));
} else {
return new DBProviderB(new EF_DBEntities(
ConfigurationManager.ConnectionStrings["EF_DB_b_conn2"]
.ToString()));
}
};
);
//later...
var db = kernel.Get(
new Ninject.Parameters.Parameter("idNum", idNum, true)
);