Exemple #1
0
        static void Main(string[] args)
        {
            WebHost host = new WebHost();

            host.IsWindowsServices = true;
            WebHost.Title          = "Service Management";
            WebHost.HeaderModel    = "beetlex-process-header";
            WebHost.HomeModel      = "beetlex-process-home";
            WebHost.TabsEnabled    = false;
            host.RegisterComponent <Program>();
            host.RegisterComponent <BeetleX.ServicesProcess.ProcessCenter>();
            host.UseFontawesome();
            host.UseElement(PageStyle.Element);
            host.Setting(o =>
            {
                o.SetDebug();
                o.Port     = 80;
                o.LogLevel = LogType.Info;
            });
            host.Initialize((http, vue, rec) =>
            {
                BeetleX.ServicesProcess.WebController controller = new BeetleX.ServicesProcess.WebController();
                controller.Init(new logHandler(http));
                http.ActionFactory.Register(controller, new BeetleX.FastHttpApi.ControllerAttribute {
                    BaseUrl = "process"
                });
                rec.AddCss("website.css");
                vue.Debug();
            });
            host.Run();
        }
Exemple #2
0
    public IWebHost Build()
    {
        if (_webHostBuilt)
        {
            throw new InvalidOperationException(Resources.WebHostBuilder_SingleInstance);
        }
        _webHostBuilt = true;

        var hostingServices        = BuildCommonServices(out var hostingStartupErrors);
        var applicationServices    = hostingServices.Clone();
        var hostingServiceProvider = GetProviderFromFactory(hostingServices);

        if (!_options.SuppressStatusMessages)
        {
            // Warn about deprecated environment variables
            if (Environment.GetEnvironmentVariable("Hosting:Environment") != null)
            {
                Console.WriteLine("The environment variable 'Hosting:Environment' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'");
            }

            if (Environment.GetEnvironmentVariable("ASPNET_ENV") != null)
            {
                Console.WriteLine("The environment variable 'ASPNET_ENV' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'");
            }

            if (Environment.GetEnvironmentVariable("ASPNETCORE_SERVER.URLS") != null)
            {
                Console.WriteLine("The environment variable 'ASPNETCORE_SERVER.URLS' is obsolete and has been replaced with 'ASPNETCORE_URLS'");
            }
        }

        AddApplicationServices(applicationServices, hostingServiceProvider);

        var host = new WebHost(
            applicationServices,
            hostingServiceProvider,
            _options,
            _config,
            hostingStartupErrors);

        try
        {
            host.Initialize();

            // resolve configuration explicitly once to mark it as resolved within the
            // service provider, ensuring it will be properly disposed with the provider
            _ = host.Services.GetService <IConfiguration>();

            var logger = host.Services.GetRequiredService <ILogger <WebHost> >();

            // Warn about duplicate HostingStartupAssemblies
            var assemblyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            foreach (var assemblyName in _options.GetFinalHostingStartupAssemblies())
            {
                if (!assemblyNames.Add(assemblyName))
                {
                    logger.LogWarning($"The assembly {assemblyName} was specified multiple times. Hosting startup assemblies should only be specified once.");
                }
            }

            return(host);
        }
        catch
        {
            // Dispose the host if there's a failure to initialize, this should dispose
            // services that were constructed until the exception was thrown
            host.Dispose();
            throw;
        }