/// <summary>
 /// .NET Core 3.0 disables IStartup and multiple Configure* entry points on Startup class requiring the use of a
 /// clean ModularStartupActivator adapter class for implementing https://docs.servicestack.net/modular-startup
 /// </summary>
 public static IWebHostBuilder UseModularStartup <TStartup>(this IWebHostBuilder hostBuilder)
     where TStartup : class
 {
     return(hostBuilder
            // UserSecrets not loaded when using surrogate startup class, load explicitly from TStartup.Assembly
            .ConfigureAppConfiguration((ctx, config) =>
                                       config.AddUserSecrets(typeof(TStartup).GetTypeInfo().Assembly, optional: true))
            .UseStartup(ModularStartup.Create <TStartup>()));
 }
예제 #2
0
            public ModularCreateStartup(IConfiguration configuration)
            {
                Configuration = configuration;
                var ci = StartupType.GetConstructor(new[] { typeof(IConfiguration) });

                if (ci != null)
                {
                    instance = (ModularStartup)ci.Invoke(new[] { Configuration });
                }
                else
                {
                    ci = StartupType.GetConstructor(Type.EmptyTypes);
                    if (ci != null)
                    {
                        instance = (ModularStartup)ci.Invoke(TypeConstants.EmptyObjectArray);
                        instance.Configuration = configuration;
                    }
                    else
                    {
                        throw new NotSupportedException($"{StartupType.Name} does not have a {StartupType.Name}(IConfiguration) constructor");
                    }
                }
            }
예제 #3
0
 public static IWebHostBuilder UseModularStartup <TStartup>(this IWebHostBuilder hostBuilder)
     where TStartup : class
 {
     return(hostBuilder.UseStartup(ModularStartup.Create <TStartup>()));
 }