我使用ASP.NET MVC和Ninject.I尝试使用模型绑定器中的ninject进行属性注入。但它不起作用。我该怎么办?
/* Model Binding */
public class CartModelBinder:IModelBinder
{
[Inject]
public ICartService CartService { get; set; }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
/* CartService is null here */
Cart cart = new Cart();
cart.CartItems = CartService.GetAll(userId);
}
}
/* Ninject */
private void AllBllBindings(){
_kernel = new StandardKernel();
_kernel.Bind<ICartService>()
.To<CartManager>()
.WithConstructorArgument("cartDal", new EfCartDal());
}