我试图在azure上设置我的web api,Everything正在本地工作,但是当我部署到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;
}}
感谢您的帮助。
答案 0 :(得分:1)
打开自定义错误消息后,我发现如果其中一个注入的依赖项引发异常,您将收到上面的错误消息。但原始错误消息将在内部异常中,您可以通过从web.config中关闭自定义错误来查看