Unity IoC does not inject dependency into Web API Controller

前端 未结 4 2004
北荒
北荒 2020-12-18 18:50

I\'m very new to using Unity, but my problem is that whenever I call my web service, I get an exception stating that

\"Make sure that the controller has a parameterl

4条回答
  •  自闭症患者
    2020-12-18 19:28

    Your Unity container is probably getting disposed because it's only defined in the scope of your WebApiConfig.Register() method. If you define your container as a member of Global, which will keep your container around for the lifetime of the app, it should work.

    Edit: also don't forget to dispose the container on Application_End.

提交回复
热议问题