I’m using Ninject as my IoC container. I have a few instances where I need to configure the injected service at runtime, so I need to pass in constructor arguments. I’m currently doing something like this:
var service = Kernel.Get<MyService>(new ConstructorArgument("paramName", runtimeInstance);
The injected parameter "paramName"
is a magic string that is not refactoring-friendly nor strongly-typed.
Is there a way to somehow use nameof(aMethodParameter)
, or an equivalent expression, to get the name of the constructor parameter so that it’s no longer a “magic string”?