Represents a set of workspaces. Two attempts to load a workspace with the same parameters, in the same WorkspaceCollection, will return the exact same instance, unless the Reset() method is called.
Namespace: Metalama.Framework.Workspaces
Assembly: Metalama.Framework.Workspaces.dll
Syntax
public sealed class WorkspaceCollectionRemarks
The WorkspaceCollection provides caching of loaded workspaces. When you call Load(params string[]) or LoadAsync(ImmutableArray<string>, ImmutableDictionary<string, string>?, bool, CancellationToken) with the same paths and properties, the collection returns the previously loaded Workspace instead of reloading it. This improves performance and ensures that multiple parts of your application can share the same workspace instance.
Use the Default property to access the default collection, or create a new instance with a custom service provider.
Constructors
| Name | Description |
|---|---|
| WorkspaceCollection(GlobalServiceProvider?) | Initializes a new instance of the WorkspaceCollection class. |
Properties
| Name | Description |
|---|---|
| Default | Gets the default instance of the WorkspaceCollection class. This is a singleton instance constructed without specifying a service provider. |
| IgnoreLoadErrors | |
| ServiceBuilder | Gets the service builder for the current collection. Use this to register custom services that will be available to all workspaces in this collection. |
Methods
| Name | Description |
|---|---|
| Load(params string[]) | Synchronously loads a set of projects or solutions into a Workspace, or returns an existing workspace if the method has been previously called with the exact same parameters. |
| LoadAsync(ImmutableArray<string>, ImmutableDictionary<string, string>?, bool, CancellationToken) | Asynchronously loads a set of projects or solutions into a Workspace, or returns an existing workspace if the method has been previously called with the exact same parameters. This overload allows specifying MSBuild properties. |
| LoadAsync(params string[]) | Asynchronously loads a set of projects or solutions into a Workspace, or returns an existing workspace if the method has been previously called with the exact same parameters. |
| Reset() | Removes all cached workspaces, but not the set of registered services. After calling this method, subsequent calls to Load(params string[]) or LoadAsync(ImmutableArray<string>, ImmutableDictionary<string, string>?, bool, CancellationToken) will reload workspaces from disk. |
| TryFindProject(Compilation, out Workspace?, out Project?, out bool) | Finds the Workspace and Project that defines a given Roslyn Compilation in the current WorkspaceCollection. |
| WithServices(Action<ServiceBuilder>) | Configures additional services for this collection, resetting any previously registered services, and returns the current collection. |