Skip to content

Commit

Permalink
AbstractMultiLifeComponent -> AbstractMultiLifeComponent<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
davkean committed Nov 14, 2018
1 parent 1b3f03a commit 98983ea
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static MultiLifetimeComponent Create()
return new MultiLifetimeComponent(joinableTaskContextNode);
}

public class MultiLifetimeComponent : AbstractMultiLifetimeComponent
public class MultiLifetimeComponent : AbstractMultiLifetimeComponent<IMultiLifetimeInstance>
{
public MultiLifetimeComponent(JoinableTaskContextNode joinableTaskContextNode)
: base(joinableTaskContextNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet

internal partial class PackageRestoreInitiator
{
private class PackageRestoreInitiatorInstance : OnceInitializedOnceDisposedAsync, IMultiLifetimeInstance
internal class PackageRestoreInitiatorInstance : OnceInitializedOnceDisposedAsync, IMultiLifetimeInstance
{
private readonly IUnconfiguredProjectVsServices _projectVsServices;
private readonly IVsSolutionRestoreService _solutionRestoreService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.NuGet
/// </summary>
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[AppliesTo(ProjectCapability.PackageReferences)]
internal partial class PackageRestoreInitiator : AbstractMultiLifetimeComponent, IProjectDynamicLoadComponent
internal partial class PackageRestoreInitiator : AbstractMultiLifetimeComponent<PackageRestoreInitiator.PackageRestoreInitiatorInstance>, IProjectDynamicLoadComponent
{
private readonly IUnconfiguredProjectVsServices _projectVsServices;
private readonly IVsSolutionRestoreService _solutionRestoreService;
Expand All @@ -35,7 +35,7 @@ public PackageRestoreInitiator(
_logger = logger;
}

protected override IMultiLifetimeInstance CreateInstance()
protected override PackageRestoreInitiatorInstance CreateInstance()
{
return new PackageRestoreInitiatorInstance(_projectVsServices, _solutionRestoreService, _activeConfigurationGroupService, _logger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies
{
internal partial class SDKVersionTelemetryServiceComponent
{
protected class SDKVersionTelemetryServiceInstance : OnceInitializedOnceDisposedAsync, IMultiLifetimeInstance
internal class SDKVersionTelemetryServiceInstance : OnceInitializedOnceDisposedAsync, IMultiLifetimeInstance
{
private readonly IUnconfiguredProjectVsServices _projectVsServices;
private readonly ISafeProjectGuidService _projectGuidService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies
/// </summary>
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[AppliesTo(ProjectCapability.DotNet)]
internal partial class SDKVersionTelemetryServiceComponent : AbstractMultiLifetimeComponent, IProjectDynamicLoadComponent
internal partial class SDKVersionTelemetryServiceComponent : AbstractMultiLifetimeComponent<SDKVersionTelemetryServiceComponent.SDKVersionTelemetryServiceInstance>, IProjectDynamicLoadComponent
{
private readonly IUnconfiguredProjectVsServices _projectVsServices;
private readonly ITelemetryService _telemetryService;
Expand All @@ -32,7 +32,7 @@ public SDKVersionTelemetryServiceComponent(
_unconfiguredProjectTasksService = unconfiguredProjectTasksService;
}

protected override IMultiLifetimeInstance CreateInstance()
protected override SDKVersionTelemetryServiceInstance CreateInstance()
=> new SDKVersionTelemetryServiceInstance(
_projectVsServices,
_projectGuidService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ namespace Microsoft.VisualStudio.ProjectSystem
/// An <see langword="abstract"/> base class that simplifies the lifetime of
/// a component that is loaded and unloaded multiple times.
/// </summary>
internal abstract class AbstractMultiLifetimeComponent : OnceInitializedOnceDisposedAsync
internal abstract class AbstractMultiLifetimeComponent<T> : OnceInitializedOnceDisposedAsync
where T : IMultiLifetimeInstance
{
private readonly object _lock = new object();
private TaskCompletionSource<object> _loadedSource = new TaskCompletionSource<object>();
private IMultiLifetimeInstance _instance;
private T _instance;

protected AbstractMultiLifetimeComponent(JoinableTaskContextNode joinableTaskContextNode)
: base(joinableTaskContextNode)
{
}

public IMultiLifetimeInstance Instance
public T Instance
{
get { return _instance; }
}

/// <summary>
/// Gets a task that is completed when current <see cref="AbstractMultiLifetimeComponent"/> has
/// Gets a task that is completed when current <see cref="AbstractMultiLifetimeComponent{T}"/> has
/// completed loading.
/// </summary>
/// <remarks>
/// The returned <see cref="Task"/> is canceled when the <see cref="AbstractMultiLifetimeComponent"/>
/// The returned <see cref="Task"/> is canceled when the <see cref="AbstractMultiLifetimeComponent{T}"/>
/// is disposed.
/// </remarks>
public Task Loaded
Expand Down Expand Up @@ -77,7 +78,7 @@ public Task UnloadAsync()
if (_instance != null)
{
instance = _instance;
_instance = null;
_instance = default;
_loadedSource = new TaskCompletionSource<object>();
}
}
Expand Down Expand Up @@ -105,6 +106,6 @@ protected override Task InitializeCoreAsync(CancellationToken cancellationToken)
/// <summary>
/// Creates a new instance of the underlying <see cref="IMultiLifetimeInstance"/>.
/// </summary>
protected abstract IMultiLifetimeInstance CreateInstance();
protected abstract T CreateInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
/// Represents an instance that is automatically initialized when its parent <see cref="AbstractMultiLifetimeComponent"/>
/// Represents an instance that is automatically initialized when its parent <see cref="AbstractMultiLifetimeComponent{Task}"/>
/// is loaded, or disposed when it is unloaded.
/// </summary>
internal interface IMultiLifetimeInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices
/// </summary>
[Export(typeof(IImplicitlyActiveService))]
[AppliesTo(ProjectCapability.DotNetLanguageService2)]
internal partial class WorkspaceContextHost : AbstractMultiLifetimeComponent, IImplicitlyActiveService, IWorkspaceProjectContextHost
internal partial class WorkspaceContextHost : AbstractMultiLifetimeComponent<WorkspaceContextHost.WorkspaceContextHostInstance>, IImplicitlyActiveService, IWorkspaceProjectContextHost
{
private readonly ConfiguredProject _project;
private readonly IProjectThreadingService _threadingService;
Expand Down Expand Up @@ -77,14 +77,14 @@ private async Task<WorkspaceContextHostInstance> GetLoadedInstanceAsync()
{
await Loaded;

var instance = (WorkspaceContextHostInstance)Instance;
WorkspaceContextHostInstance instance = Instance;
if (instance == null) // Unloaded between being Loaded and here
throw new OperationCanceledException();

return instance;
}

protected override IMultiLifetimeInstance CreateInstance()
protected override WorkspaceContextHostInstance CreateInstance()
{
return new WorkspaceContextHostInstance(_project, _threadingService, _tasksService, _projectSubscriptionService, _workspaceProjectContextProvider, _activeWorkspaceProjectContextTracker, _applyChangesToWorkspaceContextFactory);
}
Expand Down

0 comments on commit 98983ea

Please sign in to comment.