Ninject属性依赖注入不起作用

时间:2015-01-27 03:34:45

标签: c# asp.net-mvc visual-studio model-view-controller ninject

我使用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());   
    }

0 个答案:

没有答案