使用ToConstant
从此Ninject代码中Simpleinjection中的等效代码是什么。
Func<Type, IValidator> validatorFactory = type =>
{
var valType = typeof(Validator<>).MakeGenericType(type);
return (IValidator)kernel.Get(valType);
};
kernel.Bind<IValidationProvider>().ToConstant(new ValidationProvider(validatorFactory));
答案 0 :(得分:0)
RegisterInstance
是与Ninject ToConstant
等效的简单注入者:
Func<Type, IValidator> validatorFactory = type =>
{
var valType = typeof(Validator<>).MakeGenericType(type);
return (IValidator)container.GetInstance(valType);
};
container.RegisterInstance<IValidationProvider>(new ValidationProvider(validatorFactory));