Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 2.68 KB

services.md

File metadata and controls

31 lines (20 loc) · 2.68 KB
uid
services

Services

The xref:ZeroInstall.Services namespace provides services for solving dependencies, downloading implementations, executing apps, etc..

Dependency injection

The xref:ZeroInstall.Services.ServiceProvider class provides instances of various services. You can think of it as a hard-coded dependency injection container. We use this instead of a runtime DI system to avoid the performance impact of reflection, keeping the cold-start time short. This is important so that starting a cached program with 0install run does not add a significant overhead when compared to launching it directly.

To instantiate the service provider you need to provide the constructor with an xref:NanoByte.Common.Tasks.ITaskHandler. You should use exactly one instance of the service provider per user request to ensure consistent state during execution. Rather than instantiating the service provider class, another pattern used in the Zero Install code-base is to inherit from it.

You can also use the .AddZeroInstall() extension method for IServiceCollection to replace the service provider with .NET's built-in DI framework.

Sample use-case

A simplified version of the 0install run logic can be implemented using the Zero Install services as follows:

  1. Pass xref:ZeroInstall.Model.Requirements to ISolver.Solve() and get xref:ZeroInstall.Model.Selection.Selections.
  2. Pass xref:ZeroInstall.Model.Selection.Selections to ISelectionsManager.GetUncachedImplementations() and get uncached xref:ZeroInstall.Model.Implementation.
  3. Pass xref:ZeroInstall.Model.Implementation to IFetcher.Fetch(). v Pass xref:ZeroInstall.Model.Selection.Selections to IExecutor.Start().

Sample code for implementing this in various languages: