I am trying to implement Ninject on an existing class that have a bool parameter in the constructor
public MyClass(bool val) //[OPTION 1: Current]
{
//I Called static function to do something -> I want to inject this
...
if(val){ ... } else{ ... }
...
}
I want to change the logic to inject ISomething
.... the ctor will look like:
public MyClass(ISomething something, bool val) //[OPTION 2: Desired]
{
something.DoSomething();
...
if(val){ ... } else{ ... }
...
}
Also I used a disposable class that, called this one: [eg. used OPTION 1 -> trying to convert to OPTION 2]
public MyMaster(bool val)
{
this.myclass = new MyClass(val); //-> now this has to be injected, how???
}
I implemented that a couple of times in a using
context with true or false parameters, like this: [eg. used OPTION 1 -> trying to convert to OPTION 2]
using(var master = new MyMaster(true)){...} //-> This need to be refactored or injected, how???
//...
using(var master = new MyMaster(false)){...} //-> This need to be refactored or injected, how???
I am kind of blocked here... because I need to inject one value and not inject the other. Maybe implementing runtime injection? Also wrapping it in a using
statement if it is needed?
NOTE: This is done in a class library that doesn't know anything about injection (Ninject
is in later layers)