What's the idea of Microsoft's "....Abstractions" Nuget packages?

Viewed 1239

Can someone explain the general idea behind providing ... Abstraction packages?

As an example, when I search for the word "hosting" in VS NuGet package manager, in the list of findings there are:

  • Microsoft.Extensions.Hosting
  • Microsoft.Extensions.Hosting.Abstractions
  • Microsoft.AspNetCore.Hosting.Server.Abstraction
  • Microsoft.AspNetCore.Hosting.Abstractions
  • Microsoft.AspNetCore.Hosting
  • Microsoft.Extensions.Hosting.WindowsServices

Are these all related? Some seem to be platform dependent (AspNetCore) while others are not? Is there a general rule that tells me when to choose which?

Suppose I want to implement BackgroundService in a .NET5 class library, which of these NuGets shall I install? (It seems that Microsoft.Extensions.Hosting.Abstractions works fine for me, but I had to try that out.)

Thanks

1 Answers

The idea is that a library or package that you provide would only reference the Abstraction packages for easier compatibility.

E.g. if you ship a company-wide NuGet package with some business logic in it or a custom client, you may want to use ILogger / ILogger<T> for logging but not actually depend on any implementation for logging (both the built-in loggers or Serilog etc.), so you can reference the logging abstractions for these interfaces.

Related