我有一个以 nullable int 作为参数的类。
public class Test
{
public Test(int? p)
{
// ......
}
// ......
}
如何使用 unity 解决它(传递 null 作为参数)?
myContainer.RegisterType<Test>(new InjectionConstructor(10));
这可以传递 10 作为值,但如果我传递 null,它会抛出异常。
编辑以使用泛型:
尝试使用 InjectionParameter 代替:
container.RegisterType<Test>(new InjectionConstructor(new InjectionParameter<int?>(null)));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)