将 Ninject ToConstant 转换为简单的注入器实现

Convert Ninject ToConstant to Simple Injector Implementation

此 Ninject 代码使用 ToConstant 在 Simpleinjection 中的等效代码是什么。

Func<Type, IValidator> validatorFactory = type =>
{
    var valType = typeof(Validator<>).MakeGenericType(type);
    return (IValidator)kernel.Get(valType);
};

kernel.Bind<IValidationProvider>().ToConstant(new ValidationProvider(validatorFactory));

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));