Reputation: 61
I'm trying to setup my web api on azure, Everything is working file locally but when i deploy to azure I get the following error message :
An error occurred when trying to create a controller of type 'DestinationController'. Make sure that the controller has a parameterless public constructor.
The website is a normal azure website, not a worker rule.
This is my Autofac bootstraper class:
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;
And my Controller:
public class DestinationController : ApiController
{
private readonly IDestinationService _destinationService;
public DestinationController(IDestinationService destinationService)
{
this._destinationService = destinationService;
}}
Thanks for your help.
Upvotes: 1
Views: 528
Reputation: 61
After turning on the custom error messages, I found out if one of the injected dependencies throws an exception, you will get the error message above. But the original error message will be in the inner-exception, which you can see by turning custom errors off from web.config
Upvotes: 1