Через несколько часов у меня все заработало!Как и следовало ожидать, это было что-то более глубокое:
Мой контроллер выдал эту ошибку:
no parameterless constructor defined for this object
Несмотря на настройку регистрации типа IoC:
source.Register(c => MyDbContextMock.Create())
.AsImplementedInterfaces()
.InstancePerRequest();
Я былоднако отсутствует эта строка:
source.RegisterApiControllers(typeof(OrderController).Assembly);
Полный запуск настроен с впрыском:
public class ApiSelfHost : Startup
{
public override void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
var httpConfiguration = new HttpConfiguration();
var container = httpConfiguration.ConfigureAutofac();
app.UseAutofacMiddleware(container);
app.UseAutofacWebApi(httpConfiguration);
app.UseWebApi(httpConfiguration);
}
}
Где ConfigureAutofac
является расширением HttpConfiguration
:
internal static IContainer ConfigureAutofac(this HttpConfiguration source)
{
var container = new ContainerBuilder()
.ConfigureAutofac()
.Build();
source.ConfigureDependencyInjection(container);
return container;
}
И еще один ContainerBuilder
:
internal static ContainerBuilder ConfigureAutofac(this ContainerBuilder source)
{
source.RegisterApiControllers(typeof(OrderController).Assembly);
source.Register(c => MyDbContextMock.Create())
.AsImplementedInterfaces()
.InstancePerRequest();
return source;
}
Startup
базовый класс является актуальным из API.