public static IEnumerable <Type> GetModuleStartupTypes(string entryAssemblyName, string environmentName) { var entryAssembly = Assembly.Load(new AssemblyName(entryAssemblyName)); var context = DependencyContext.Load(entryAssembly); return(context.RuntimeLibraries .Where(lib => lib.Name != entryAssemblyName) .SelectMany(lib => lib.GetDefaultAssemblyNames(context)) .Select(assemblyName => ModuleStartupLoader.FindStartupType(assemblyName.Name, environmentName)) .Where(type => type != null) .ToList()); }
IModuleStartup GetModuleStartup() { if (typeof(IModuleStartup).GetTypeInfo().IsAssignableFrom(ModuleStartupType)) { ModuleServiceCollection.AddSingleton(typeof(IModuleStartup), ModuleStartupType); } else { ModuleServiceCollection.AddSingleton <IModuleStartup>(sp => { var hostingEnvironment = sp.GetRequiredService <IHostingEnvironment>(); return(new ConventionBasedModuleStartup( ModuleStartupLoader.LoadMethods(sp, ModuleStartupType, hostingEnvironment.EnvironmentName))); }); } var moduleHostingServiceProvider = ModuleServiceCollection.BuildServiceProvider(); return(moduleHostingServiceProvider.GetRequiredService <IModuleStartup>()); }