private Type GetStartupType(Assembly assembly) { bool IsAConventionBasedStartupClass(Type t) { return(t.Name.StartsWith("Startup") && !t.GetTypeInfo().IsAbstract && MethodLoader.TryGetMethodInfo <IServiceCollection>(t, nameof(IStartup.ConfigureServices), out var @delegate)); } var startupTypes = assembly? .GetTypes() .Where(t => t.GetTypeInfo().BaseType == typeof(IStartup) || IsAConventionBasedStartupClass(t)) .ToList(); if (!startupTypes.Any()) { throw new InvalidOperationException("There is no Startup class"); } var startupType = startupTypes .Where(st => st.Name == $"Startup_{_environment.EnvironmentName}") .FirstOrDefault() ?? startupTypes .Where(st => st.Name == "Startup") .First(); return(startupType); }
private Action GetConfigureServicesdDelegateAsAction(object instance, IServiceCollection serviceCollection) { if (MethodLoader.TryGetMethodInfo <IServiceCollection>(instance.GetType(), $"Configure{_environment.EnvironmentName}Services", out var configureServicesMethod)) { return(MethodLoader.GetMethod(instance, $"Configure{_environment.EnvironmentName}Services", serviceCollection)); } else { return(MethodLoader.GetMethod(instance, nameof(IStartup.ConfigureServices), serviceCollection)); } }