-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make custom ApplicationName work for hosting and user secrets #52305
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
using System.Buffers; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
@@ -76,7 +77,7 @@ private static ApplicationPartManager GetApplicationPartManager(IServiceCollecti | |
{ | ||
manager = new ApplicationPartManager(); | ||
|
||
var entryAssemblyName = environment?.ApplicationName; | ||
var entryAssemblyName = GetEntryAssemblyName(environment); | ||
if (string.IsNullOrEmpty(entryAssemblyName)) | ||
{ | ||
return manager; | ||
|
@@ -86,6 +87,24 @@ private static ApplicationPartManager GetApplicationPartManager(IServiceCollecti | |
} | ||
|
||
return manager; | ||
|
||
static string? GetEntryAssemblyName(IWebHostEnvironment? environment) | ||
{ | ||
if (environment is null) | ||
{ | ||
return null; | ||
} | ||
|
||
try | ||
{ | ||
_ = Assembly.Load(new AssemblyName(environment.ApplicationName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really happy with that solution. What if we extend Also the logic for determing the correct assembly name is only in one place. |
||
return environment.ApplicationName; | ||
} | ||
catch | ||
{ | ||
return Assembly.GetEntryAssembly()?.GetName().Name; | ||
} | ||
} | ||
} | ||
|
||
private static T? GetServiceFromCollection<T>(IServiceCollection services) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In unit tests this can be
testhost
, but that's no problem as the user secrets are reigstered asoptional
, thus if the attribute for user sectes doesn't exist, it's just ignored.Besides that is there any other reliable way to probe for existance of an assembly?