This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Startup.cs
97 lines (85 loc) · 3.34 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Quantum.IQSharp.Kernel;
using Microsoft.Quantum.IQSharp.AzureClient;
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Build.Locator;
namespace Microsoft.Quantum.IQSharp
{
/// <summary>
/// StartUp class used when starting as a WebHost (http server)
/// </summary>
public class Startup
{
private readonly IConfiguration Configuration;
// We need to make sure that MSBuild is located exactly once; either
// failing to call `.RegisterDefaults` or calling it twice will cause
// an exception.
private static readonly Lazy<VisualStudioInstance?> visualStudioInstance = new(() =>
{
try
{
return MSBuildLocator.RegisterDefaults();
}
catch
{
return null;
}
});
public static VisualStudioInstance? VisualStudioInstance => visualStudioInstance.Value;
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public virtual void ConfigureServices(IServiceCollection services)
{
// NB: MSBuildLocator must be used as early as possible, so we
// run it as services are being configured.
if (VisualStudioInstance is {} vsi)
{
services.AddSingleton<CompilerService.MSBuildMetadata>(new CompilerService.MSBuildMetadata(
Version: vsi.Version,
RootPath: vsi.VisualStudioRootPath,
Name: vsi.Name,
Path: vsi.MSBuildPath
));
}
services.Configure<Workspace.Settings>(Configuration);
services.Configure<NugetPackages.Settings>(Configuration);
services.Configure<References.Settings>(Configuration);
services.Configure<CompilerService.Settings>(Configuration);
services.Configure<IQSharpEngine.Settings>(Configuration);
services.Configure<ClientInformation>(Configuration);
services.AddSingleton(typeof(ITelemetryService), GetTelemetryServiceType());
services.AddIQSharp();
services.AddIQSharpKernel();
services.AddAzureClient();
var assembly = typeof(PackagesController).Assembly;
services.AddControllers()
.AddApplicationPart(assembly);
}
private Type GetTelemetryServiceType()
{
return
#if TELEMETRY
Program.TelemetryOptOut ? typeof(NullTelemetryService) : typeof(TelemetryService);
#else
typeof(NullTelemetryService);
#endif
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}