I have a class that takes nullable int as parameter.
public class Test
{
public Test(int? p)
{
// ......
}
// ......
}
How do I resolve it using unity (passing null as parameter)?
myContainer.RegisterType<Test>(new InjectionConstructor(10));
This works passing 10 as value, but if I pass null, it throws exception.
Edited to use generics:
Try to use InjectionParameter instead:
container.RegisterType<Test>(new InjectionConstructor(new InjectionParameter<int?>(null)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With