Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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));
     }
 }