Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 954
KarloX Avatar asked Nov 01 '20 07:11

KarloX


People also ask

What is the significance of using NuGet packages?

NuGet provides the tools developers need for creating, publishing, and consuming packages. Most importantly, NuGet maintains a reference list of packages used in a project and the ability to restore and update those packages from that list.

What are the NuGet packages?

NuGet is a package manager that delivers compiled source code (DLLs) and other files (scripts and images) related to code. A NuGet package takes the form of a zip file with the extension . nupkg. This makes adding, updating, and removing libraries easy in Visual Studio applications.

What is the purpose of the NuGet package manager in asp net core?

The NuGet Package Manager can be used to search and install NuGet packages in the Visual Studio solution or project. Right-click the project or solution in the Solution Explorer tab, and choose Manage NuGet Packages… Alternatively, click Tools, menu, NuGet Package Manager | Manage NuGet Packages for Solution...


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.

like image 89
Martin Ullrich Avatar answered Oct 01 '22 00:10

Martin Ullrich