Created
June 6, 2018 09:48
-
-
Save configureappio/747c751b461019405ea038060e865e88 to your computer and use it in GitHub Desktop.
Snippet from MvcCoreServiceCollectionExtensions to show how the ApplicationName in the environment controls where controllers are looked for
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
public static class MvcCoreServiceCollectionExtensions | |
{ | |
public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services) | |
{ | |
if (services == null) | |
{ | |
throw new ArgumentNullException(nameof(services)); | |
} | |
var partManager = GetApplicationPartManager(services); | |
services.TryAddSingleton(partManager); | |
ConfigureDefaultFeatureProviders(partManager); | |
ConfigureDefaultServices(services); | |
AddMvcCoreServices(services); | |
var builder = new MvcCoreBuilder(services, partManager); | |
return builder; | |
} | |
private static ApplicationPartManager GetApplicationPartManager(IServiceCollection services) | |
{ | |
var manager = GetServiceFromCollection<ApplicationPartManager>(services); | |
if (manager == null) | |
{ | |
manager = new ApplicationPartManager(); | |
var environment = GetServiceFromCollection<IHostingEnvironment>(services); | |
var entryAssemblyName = environment?.ApplicationName; | |
if (string.IsNullOrEmpty(entryAssemblyName)) | |
{ | |
return manager; | |
} | |
manager.PopulateDefaultParts(entryAssemblyName); | |
} | |
return manager; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment