Ninject Property Injection Setup问题

时间:2013-05-10 21:36:39

标签: c# dependency-injection inversion-of-control ninject

这个问题涉及我之前提出的问题的答案(IoC setup and issue with inherited class)。

我已尝试设置属性注入以解决我在其他问题中的问题,但该对象始终为null。

我的设置如下:

具有属性和注入属性的类

public class Freedom2BookTree : umbraco.cms.presentation.Trees.BaseTree
{
    private IBookingService _bookingService;

    [Inject]
    public IBookingService BookingService
    {
        get { return _bookingService; }
        set { _bookingService = value; }
    }

Application Start

中的Ninject代码
// Create Ninject DI kernel
IKernel kernel = new StandardKernel();

// Register services with Ninject DI Container
kernel.Bind<IBookingService>().To<BookingService>().InRequestScope();

// Tell ASP.NET MVC 3 to use our Ninject DI Container
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

我真的很感激任何建议:)

1 个答案:

答案 0 :(得分:1)

我已经设法通过回答这个问题来解决问题:

How do I inject into some generic asp.net http handler using Ninject?