webadvanced / Structuremap.WebAPI2

Apache License 2.0
12 stars 1 forks source link

StructureMap isn't creating WebAPI controllers for some reason. #6

Open B3nCr opened 7 years ago

B3nCr commented 7 years ago

Hi

I'm struggling at the moment to work out what's going on with my app.

We've recently included an owin Startup class and I believe that's what's made StructureMap stop working.

It seems like WebAPI can't create any of my controllers and I can't see StructureMap anywhere in the stack trace so that's making me think it's not registered as the controller factory or something.

"ExceptionMessage": "Type 'GRP2App.Web.API.AuthController' does not have a default constructor",
"ExceptionType": "System.ArgumentException",
"StackTrace": "
  at System.Linq.Expressions.Expression.New(Type type)
  at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)
  at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
  at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"

What am I missing? There must be an OWIN config line that I'm missing that tells OWIN that StructureMap is my DI container and to use it to create controller instances

B3nCr commented 7 years ago

Hmm, now I've even managed to break the MVC controllers which were working fine before.

I added this to my Start.cs

config.DependencyResolver = new StructureMapWebApiDependencyResolver(IoC.Initialize());

StructureMapDependencyScope has started throwing exceptions in DoGetInstance

"Cannot access a disposed object. Object name: 'StructureMap Nested Container'."