I have a simple app which uses an OWIN-Startup class to configure itself. BUT, I'm not able to get it to work! Here is my configuration:
public void Configuration(IAppBuilder appBuilder) {
var httpConfiguration = new HttpConfiguration();
httpConfiguration.Routes.MapHttpRoute(
name: "default_api_versioned_by_areas",
routeTemplate: "api/{area}/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var container = new Container();
// registering my services. They're all good....
container.WithWebApi(
httpConfiguration, new[] {GetType().Assembly});
container.RegisterWebApiControllers(
httpConfiguration, new[] { GetType().Assembly });
appBuilder.UseDryIocWebApi(httpConfiguration)
.UseDryIocOwinMiddleware(container);
appBuilder.UseWebApi(httpConfiguration);
// I can resolve other services:
var s = container.Resolve<MyOtherService>();
// but I cannot resolve controllers:
var c = container.Resolve<ContentController>();
}
As you can see, MyOtherService
is resolvable; But not the ContentController
. Also, when I request an API, I get this error:
An error occurred when trying to create a controller of type 'ContentController'. Make sure that the controller has a parameterless public constructor.
Googling doesn't help. Can you help me to figure out how to run the app?
UPDATE:
It seems controllers are not-registered at-all. When I try to resolve the ContentController
- which has a default ctor
with no-dependency - I get this error:
// code:
var c = container.Resolve<ContentController>();
// exception:
An exception of type 'DryIoc.ContainerException' occurred in DryIoc.dll but was not handled in user code
Additional information: Unable to resolve MyProject.Areas.Alpha.Controllers.ContentController
Where CurrentScope:
and ResolutionScope:
and Found registrations:
without matching scope DefaultKey.Of(0),{ID=33, ImplType=MyProject.Areas.Alpha.Controllers.ContentController, Reuse=CurrentScopeReuse {Name="WebRequestScopeName", Lifespan=100}}}
without matching scope DefaultKey.Of(1),{ID=37, ImplType=MyProject.Areas.Alpha.Controllers.ContentController, Reuse=CurrentScopeReuse {Name="WebRequestScopeName", Lifespan=100}}}