ASP.NET WebApi + Autofac не находит ApiController

Я пытаюсь заставить Autofac работать с WebApi. У меня есть мои ApiControllers в отдельном проекте от основного веб-проекта.

InventorySystem.Web.UI InventorySystem.Web.Api.Controllers

Всякий раз, когда я пытаюсь перейти к маршруту API, я получаю ответ:

<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <ExceptionType>System.ArgumentNullException</ExceptionType>
    <Message>Value cannot be null. Parameter name: value</Message>
    <StackTrace>
at System.Web.Http.Controllers.HttpControllerContext.set_Controller(IHttpController value)
at System.Web.Http.Dispatcher.DefaultHttpControllerFactory.CreateInstance(HttpControllerContext controllerContext, HttpControllerDescriptor controllerDescriptor)
at System.Web.Http.Dispatcher.DefaultHttpControllerFactory.CreateController(HttpControllerContext controllerContext, String controllerName)
at Autofac.Integration.WebApi.AutofacControllerFactory.CreateController(HttpControllerContext controllerContext, String controllerName)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    </StackTrace>
</Exception>

Когда я просматриваю код Autofac, я вижу, что мой контроллер зарегистрирован, но AutofacControllerActivator.Create ()возвращает ноль. В частности, линия return (ResolutionExtensions.ResolveOptional (scope, controllerType )as IHttpController );

Код автофака :string binDirectory = Path.Combine (HttpRuntime.AppDomainAppPath, "bin" );

        var builder = new ContainerBuilder();

        builder.ConfigureWebApi(GlobalConfiguration.Configuration);

        builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
        builder.RegisterApiControllers(Assembly.LoadFile(Path.Combine(binDirectory, "InventorySystem.Web.Api.dll"))).PropertiesAutowired();
        builder.RegisterFilterProvider();            

        var container = builder.Build();

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        GlobalConfiguration.Configuration.ServiceResolver.SetResolver(new AutofacWebApiDependencyResolver(container));

Я что-то пропустил?

Спасибо

5
задан user695595 27 April 2012 в 00:42
поделиться