-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm mainly putting this up so @DustinCampbell can tell me what I did wrong :) As part of cohosting we're going to need a lot more things to run in OOP, so its probably best to move away from these hand-constructed services that it has. This PR introduced MEF, in a reasonably unsophisticated way, into the procedure so that services can at least get some things from an `ExportProvider`. Once in that world, obviously everything works as expected with attributes etc. Along the way I also found that our telemetry reporting in OOP wasn't doing anything, so fixed that and moved it to the MEF composition too. Also improved the `launchSettings.json` file a little, and found it was previously in the `.gitignore`. This seemed wrong to me, but maybe @dotnet/razor-compiler will have something different to say about that? I can always move the compiler one back in if necessary. Part of #9519
- Loading branch information
Showing
12 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
launchSettings.json | ||
|
||
# Build results | ||
artifacts/ | ||
|
12 changes: 12 additions & 0 deletions
12
...osoft.AspNetCore.Razor.Microbenchmarks.Generator/SampleApp/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"SampleApp": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53331;http://localhost:53332" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RazorServiceFactoryBase.ExportProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Composition; | ||
using Microsoft.VisualStudio.Threading; | ||
|
||
namespace Microsoft.CodeAnalysis.Remote.Razor; | ||
|
||
internal abstract partial class RazorServiceFactoryBase<TService> | ||
{ | ||
internal static readonly ImmutableArray<Assembly> RemoteHostAssemblies = [typeof(RazorServiceFactoryBase<TService>).Assembly]; | ||
|
||
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed | ||
private static readonly AsyncLazy<ExportProvider> s_exportProviderLazy = new(GetExportProviderAsync); | ||
#pragma warning restore VSTHRD012 // Provide JoinableTaskFactory where allowed | ||
|
||
// Inspired by https://github.com/dotnet/roslyn/blob/25aa74d725e801b8232dbb3e5abcda0fa72da8c5/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspaceManager.cs#L77 | ||
private static async Task<ExportProvider> GetExportProviderAsync() | ||
{ | ||
var resolver = Resolver.DefaultInstance; | ||
var discovery = new AttributedPartDiscovery(resolver, isNonPublicSupported: true); // MEFv2 only | ||
var parts = await discovery.CreatePartsAsync(RemoteHostAssemblies).ConfigureAwait(false); | ||
var catalog = ComposableCatalog.Create(resolver).AddParts(parts); | ||
|
||
var configuration = CompositionConfiguration.Create(catalog).ThrowOnErrors(); | ||
var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration); | ||
var exportProviderFactory = runtimeComposition.CreateExportProviderFactory(); | ||
return exportProviderFactory.CreateExportProvider(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Telemetry/OutOfProcessTelemetryReporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Composition; | ||
using Microsoft.AspNetCore.Razor.Telemetry; | ||
using Microsoft.VisualStudio.Telemetry; | ||
|
||
namespace Microsoft.CodeAnalysis.Remote.Razor.Telemetry; | ||
|
||
[Export(typeof(ITelemetryReporter)), Shared] | ||
internal class OutOfProcessTelemetryReporter : TelemetryReporter | ||
{ | ||
public OutOfProcessTelemetryReporter() | ||
: base([TelemetryService.DefaultSession]) | ||
{ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/Razor/src/Microsoft.VisualStudio.RazorExtension/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"profiles": { | ||
"Razor": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"CPS_DiagnosticRuntime": "1", | ||
"CPS_MetricsCollection": "1", | ||
"ServiceHubTraceLevel": "All", | ||
}, | ||
"nativeDebugging": true | ||
}, | ||
"Razor (with ServiceHub debugging)": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"CPS_DiagnosticRuntime": "1", | ||
"CPS_MetricsCollection": "1", | ||
"ServiceHubTraceLevel": "All", | ||
"SERVICEHUBDEBUGHOSTONSTARTUP": "ServiceHub.RoslynCodeAnalysisService.exe" | ||
}, | ||
"nativeDebugging": true | ||
} | ||
} | ||
} |