AspNetDependencyInjection icon indicating copy to clipboard operation
AspNetDependencyInjection copied to clipboard

Connect to ASP.Net WebAPI DependencyResolver

Open watfordgnf opened this issue 4 years ago • 3 comments

This connects the WebApi dependency resolver to ASP.Net WebApi, just like is done for WebForms. This also ensures that optional dependencies do not throw. This was the bare minimum change to this project that enabled it to work for our service.

watfordgnf avatar Apr 14 '21 20:04 watfordgnf

Same issue here. Thanks for this fix.

ditchcode avatar May 25 '21 00:05 ditchcode

Thank you for the PR and I apologize for not reviewing it first as I've already fixed it in my own branches and published the updated packages as version 5.0.0-beta01 which fixes this issue (and many others...) in the sample projects in the repo.

https://www.nuget.org/packages/Jehoel.AspNetDependencyInjection/5.0.0-beta01 https://www.nuget.org/packages/Jehoel.AspNetDependencyInjection.Mvc/5.0.0-beta01 https://www.nuget.org/packages/Jehoel.AspNetDependencyInjection.WebApi/5.0.0-beta01

Can you give it a try and if it works great then I'll make 5.0.0 public right-away.


In my approach, I opted to use reflection to get GlobalConfiguration.Configuration so we can avoid needing a hard assembly-reference and NuGet package reference to Microsoft.AspNet.WebApi.WebHost which is separate from the main ASP.NET Web API NuGet package - my approach also allows users to pass-in their own HttpConfiguration instance if they're using Web API in a self-hosted or OWIN-without-ASP.NET-hosting scenario.

Once again, my apologies for not getting back to you sooner - I hate to think I made anyone waste their time :/

I'll leave this PR open just in case further work is needed that you'd like to comment on.

daiplusplus avatar Jul 19 '21 04:07 daiplusplus

When are the non-beta 5.0.0 packages being published?

The WebApi v5.0.0-beta2 package fixed my issue, I opted to use the following method and it worked for me (v4 previously didn't work).

.AddWebApiDependencyResolver(HttpConfig)

Edit: tagging @Jehoel thanks.

nathanrobb avatar Sep 01 '21 01:09 nathanrobb