/// <summary> /// Returns the <see cref="IApplicationPartManager"/> for the provided context. /// </summary> /// <returns>The <see cref="IApplicationPartManager"/> belonging to the provided context.</returns> public static IApplicationPartManager GetApplicationPartManager(this IServiceCollection services) { var manager = GetServiceFromCollection <IApplicationPartManager>(services); if (manager is null) { manager = new ApplicationPartManager(); services.AddSingleton(manager); services.AddSingleton <IApplicationPartManager>(manager); manager.AddFromDependencyContext(); manager.AddFromAssemblyLoadContext(); if (GetServiceFromCollection <IHostEnvironment>(services)?.ApplicationName is string applicationName) { try { var entryAssembly = Assembly.Load(new AssemblyName(applicationName)); manager.AddApplicationPart(entryAssembly); } catch { // Ignore exceptions here. } } if (Assembly.GetEntryAssembly() is Assembly asm) { manager.AddApplicationPart(asm); } } return(manager); }