Skip to content

Commit d589668

Browse files
committed
Updating ExtensionbundleManager dependency from HostController
1 parent 5575abf commit d589668

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/WebJobs.Script.WebHost/Controllers/HostController.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Azure.WebJobs.Script.WebHost.Security;
2626
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authorization;
2727
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authorization.Policies;
28+
using Microsoft.Extensions.DependencyInjection;
2829
using Microsoft.Extensions.Logging;
2930
using Microsoft.Extensions.Options;
3031
using Newtonsoft.Json;
@@ -47,7 +48,6 @@ public class HostController : Controller
4748
private readonly IEnvironment _environment;
4849
private readonly IScriptHostManager _scriptHostManager;
4950
private readonly IFunctionsSyncManager _functionsSyncManager;
50-
private readonly IExtensionBundleManager _extensionBundleManager;
5151

5252
public HostController(IOptions<ScriptApplicationHostOptions> applicationHostOptions,
5353
IOptions<JobHostOptions> hostOptions,
@@ -56,8 +56,7 @@ public HostController(IOptions<ScriptApplicationHostOptions> applicationHostOpti
5656
IWebFunctionsManager functionsManager,
5757
IEnvironment environment,
5858
IScriptHostManager scriptHostManager,
59-
IFunctionsSyncManager functionsSyncManager,
60-
IExtensionBundleManager extensionBundleManager)
59+
IFunctionsSyncManager functionsSyncManager)
6160
{
6261
_applicationHostOptions = applicationHostOptions;
6362
_hostOptions = hostOptions;
@@ -67,14 +66,13 @@ public HostController(IOptions<ScriptApplicationHostOptions> applicationHostOpti
6766
_environment = environment;
6867
_scriptHostManager = scriptHostManager;
6968
_functionsSyncManager = functionsSyncManager;
70-
_extensionBundleManager = extensionBundleManager;
7169
}
7270

7371
[HttpGet]
7472
[Route("admin/host/status")]
7573
[Authorize(Policy = PolicyNames.AdminAuthLevelOrInternal)]
7674
[TypeFilter(typeof(EnableDebugModeFilter))]
77-
public async Task<IActionResult> GetHostStatus([FromServices] IScriptHostManager scriptHostManager, [FromServices] IHostIdProvider hostIdProvider)
75+
public async Task<IActionResult> GetHostStatus([FromServices] IScriptHostManager scriptHostManager, [FromServices] IHostIdProvider hostIdProvider, [FromServices] IServiceProvider serviceProvider = null)
7876
{
7977
var status = new HostStatus
8078
{
@@ -85,14 +83,18 @@ public async Task<IActionResult> GetHostStatus([FromServices] IScriptHostManager
8583
ProcessUptime = (long)(DateTime.UtcNow - Process.GetCurrentProcess().StartTime).TotalMilliseconds
8684
};
8785

88-
var bundleInfo = await _extensionBundleManager.GetExtensionBundleDetails();
89-
if (bundleInfo != null)
86+
var bundleManager = serviceProvider.GetService<IExtensionBundleManager>();
87+
if (bundleManager != null)
9088
{
91-
status.ExtensionBundle = new Models.ExtensionBundle()
89+
var bundleInfo = await bundleManager.GetExtensionBundleDetails();
90+
if (bundleInfo != null)
9291
{
93-
Id = bundleInfo.Id,
94-
Version = bundleInfo.Version
95-
};
92+
status.ExtensionBundle = new Models.ExtensionBundle()
93+
{
94+
Id = bundleInfo.Id,
95+
Version = bundleInfo.Version
96+
};
97+
}
9698
}
9799

98100
var lastError = scriptHostManager.LastError;

src/WebJobs.Script/ScriptHostBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ public static IHostBuilder AddScriptHostCore(this IHostBuilder builder, ScriptAp
107107

108108
var extensionBundleOptions = GetExtensionBundleOptions(context);
109109
var bundleManager = new ExtensionBundleManager(extensionBundleOptions, SystemEnvironment.Instance, loggerFactory);
110+
webJobsBuilder.Services.AddSingleton<IExtensionBundleManager>(_ => bundleManager);
110111
if (!skipHostInitialization)
111112
{
112113
// Only set our external startup if we're not suppressing host initialization
113114
// as we don't want to load user assemblies otherwise.
114115
webJobsBuilder.UseScriptExternalStartup(applicationHostOptions, loggerFactory, bundleManager);
115116
}
116-
webJobsBuilder.Services.AddSingleton<IExtensionBundleManager>(_ => bundleManager);
117117

118118
configureWebJobs?.Invoke(webJobsBuilder);
119119
}, o => o.AllowPartialHostStartup = true);

test/WebJobs.Script.Tests/Controllers/Admin/HostControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public HostControllerTests()
5454
_functionsSyncManager = new Mock<IFunctionsSyncManager>(MockBehavior.Strict);
5555
_extensionBundleManager = new Mock<IExtensionBundleManager>(MockBehavior.Strict);
5656

57-
_hostController = new HostController(optionsWrapper, hostOptions, loggerFactory, mockAuthorizationService.Object, mockWebFunctionsManager.Object, _mockEnvironment.Object, _mockScriptHostManager.Object, _functionsSyncManager.Object, _extensionBundleManager.Object);
57+
_hostController = new HostController(optionsWrapper, hostOptions, loggerFactory, mockAuthorizationService.Object, mockWebFunctionsManager.Object, _mockEnvironment.Object, _mockScriptHostManager.Object, _functionsSyncManager.Object);
5858

5959
_appOfflineFilePath = Path.Combine(_scriptPath, ScriptConstants.AppOfflineFileName);
6060
if (File.Exists(_appOfflineFilePath))

0 commit comments

Comments
 (0)