2014-06-30 30 views
1

我試圖建立在Azure上我的網絡API,一切都在本地工作的文件,但是當我部署到Azure,我得到了以下錯誤消息:autofac不是的WebAPI 2個工作在Azure網站

錯誤嘗試創建類型爲「DestinationController」的控制器時發生。確保控制器有一個無參數的公共構造函數。

該網站是一個普通的天藍色網站,而不是一個工人的規則。

這是我Autofac bootstraper類:

var builder = new ContainerBuilder(); 
     builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 
     builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerRequest(); 
     builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerRequest(); 
     builder.RegisterAssemblyTypes(typeof(DestinationRepository).Assembly).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces().InstancePerRequest(); 
     builder.RegisterAssemblyTypes(typeof(DestinationService).Assembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerRequest(); 

     builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration); 
     IContainer container = builder.Build(); 

     // Create the depenedency resolver. 
     var resolver = new AutofacWebApiDependencyResolver(container); 

     // Configure Web API with the dependency resolver. 
     GlobalConfiguration.Configuration.DependencyResolver = resolver; 

我的控制器:

public class DestinationController : ApiController 
{ 
    private readonly IDestinationService _destinationService; 

    public DestinationController(IDestinationService destinationService) 
    { 
     this._destinationService = destinationService; 
    }} 

感謝您的幫助。

回答

1

打開自定義錯誤消息後,我發現如果其中一個注入的依賴項拋出異常,您將看到上面的錯誤消息。但是原始的錯誤信息會出現在內部例外中,您可以通過從web.config中關閉自定義錯誤來查看原始錯誤消息。