khellang/Middleware

Call `AddProblemDetailsConventions` directly on `IServiceCollection`

lonix1 opened this issue ยท 9 comments

To use AddProblemDetailsConventions() we must do this:

services                                // returns IServiceCollection
  .AddControllers()                     // returns IMvcBuilder        <---- here's the problem
  .AddProblemDetailsConventions();

In some environments, that IMvcBuilder isn't available or easy to access. For example when using a modular startup, or Orchard Core. Other libraries also had this problem, it's quite common.

All that extension method does is call IMvcBuilder.IServiceCollection. Would it be possible to add an overload (not a breaking change!) to accept that directly:

public static IServiceCollection AddProblemDetailsConventions(this IServiceCollection services)
{
  //identical to other overload
}

We could call it like so:

services.AddProblemDetailsConventions();

I would patch this myself but I never figured out the github PR thing. :) It would be a great improvement and add major flexibility when configuring app startup.

I hope this can be considered. Thank you!

Sure, that sounds reasonable. I'll happily accept a PR if I can't get to it myself ๐Ÿ˜„

Awww heck, I messed it up again ๐Ÿคก I think my PR was applied to my fork and didn't get to this repo. Oh well I tried. It's here BTW.

Opened #151 for you ๐Ÿ˜„

Do I need to do something on my end?

(So many things to learn, so little time!)

Do I need to do something on my end?

Nope. I'll just take it for a spin and if it looks good, it's good to merge ๐Ÿ˜„ Thanks for the PR! ๐Ÿ™๐Ÿป

You mean my half-assed attempt at pretending I know how to use github properly? "You're welcome". If it breaks I'm sorry! ๐Ÿ˜„

If there's a pre-release build somewhere, let me know if you want me to beta test it.

Hey @lonix1! Sorry it took some time, but ended up pushing v6.3.0 to NuGet today ๐Ÿ˜„

Thanks for the new version! ๐Ÿ˜„