Exemple #1
0
        private static IConfigurationRoot LoadConfig <TStartup>(
            string[] args,
            string basePath)
            where TStartup : class
        {
            bool isDevelopment = WebHostWrapper.IsDevelopment();

            IConfigurationBuilder configBuilder = new ConfigurationBuilder()
                                                  .SetBasePath(basePath)
                                                  .AddJsonFile(
                path: WebHostWrapper.GetConfigFilePath(
                    basePath,
                    isDevelopment
                    ),
                optional: false,
                reloadOnChange: false);

            if (isDevelopment)
            {
                configBuilder.AddUserSecrets <TStartup>();
            }

            configBuilder.AddEnvironmentVariables();

            if (args != null)
            {
                configBuilder.AddCommandLine(args);
            }

            return(configBuilder.Build());
        }
Exemple #2
0
        /// <summary>
        /// Use this if you start identitybase from custom project
        /// </summary>
        /// <typeparam name="TStartup"></typeparam>
        /// <param name="args"></param>
        /// <param name="basePath"></param>
        public static void Start <TStartup>(
            string[] args,
            string basePath)
            where TStartup : class
        {
            IConfiguration config = WebHostWrapper
                                    .LoadConfig <TStartup>(args, basePath);

            // Use in case you changed the example data in ExampleData.cs file
            // Configuration.ExampleDataWriter.Write(config);

            IConfigurationSection configHost = config.GetSection("Host");

            IWebHostBuilder hostBuilder = new WebHostBuilder()
                                          .UseKestrel()
                                          .UseUrls(configHost.GetValue <string>("Urls"))
                                          .UseContentRoot(basePath)
                                          .UseConfiguration(config)
                                          .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddSerilog(hostingContext.Configuration);
            })
                                          .UseStartup <TStartup>();

            // if (configHost.GetValue<bool>("UseIISIntegration"))
            // {
            //     Console.WriteLine("Enabling IIS Integration");
            //     hostBuilder = hostBuilder.UseIISIntegration();
            // }

            hostBuilder
            .Build()
            .RunAsync(WebHostWrapper.cancelTokenSource.Token)
            .Wait();
        }
Exemple #3
0
 public static void Restart()
 {
     WebHostWrapper.Shutdown(2);
 }
Exemple #4
0
 public static void Start <TStartup>(string[] args)
     where TStartup : class
 {
     WebHostWrapper.Start <TStartup>(args,
                                     Directory.GetCurrentDirectory());
 }