Hosting from another project
Another project can host the web service instead of running its Main. It references the web service
project, and its own Main sets the hooks it needs, then takes the steps this Main takes from
BuildApp on. The class is HiNC_2025_webservice.Program; a hosting project whose own entry class
is also named Program refers to it by that full name or through a using alias.
The two hooks are static properties, and both default to null, which is how the web service runs
on its own:
ContentRootPath— the folderappsettings*.jsonandwwwrootare read from.nullleaves the framework's default: the working directory, or--contentRooton the command line. A value set here wins over--contentRoot, and the content root cannot change once the builder exists.ConfigureBuilder— called with theWebApplicationBuilderright afterBuildAppcreates it, beforeBuildAppreads any setting or registers any service: the place for the hosting project's own configuration sources and services. A source added there comes after the command line, so it wins over every default source unless the environment variables and the command line are added again after it. A logging provider added there does not survive:BuildAppclears the providers right after the call and adds its console and file loggers.
Then, in order:
Program.BuildApp(args)builds the application without starting it. What needs only the built application — middleware, a project to load, lifetime callbacks — goes between this call and the last; middleware added to it runs after step 7 of the request pipeline, ahead of the endpoints.- Optionally,
Program.AnnounceWhenStarted(app, version, settingsFile): once the server listens, it prints the given version and settings file, the addresses and the working directory to the console, with a line saying that closing the window stops HiNC, and on Windows puts the address in the console window's title. Under systemd — whereINVOCATION_IDis set — it leaves out the addresses and that line, since the output goes to the journal, nobody opens the site at its local address there, and there is no window to close. It opens no browser. The web service's ownMainpasses the HiNc assembly version andappsettings.json— or, where the content root has none,appsettings.{Environment}.json. Program.RunApp(app), rather thanapp.Run(): it writes the startup summary line, runs, then ends the native core and closes the log file. Without it the core is ended only when the process exits normally, which an exception out ofRunskips, leaving the licence seat taken.
The hosting project's own controllers are served beside the web service's, because MVC takes the
entry assembly as an application part. BuildApp also reads the entry assembly's XML file, so their
documentation shows in Swagger when the project builds with GenerateDocumentationFile. A
settings file named after the entry assembly, {ApplicationName}.settings.json in the content root,
joins the configuration chain after the web service's appsettings
files with no code at all. ExecutionStatusService.StatusRunning and ExecutionStatusService.StatusPaused
are public constants: a hosting project that must not act while a run is in progress or paused compares
against them, so a rename breaks its build rather than its check.
The front end's counterpart is the build-time alias product. It resolves to the web service's own
module — the menu bar's version mark, the items the Help menu appends after the Log Viewer (none), the
menu bar's cloud licence badge (none) and a last boot file (empty) — unless the SPA is built with
HINC_PRODUCT_SPA set to the absolute path of a folder with the same exports, VersionBadge,
HelpMenuItems and CloudStatusBadge; see Web Service SPA Source Tree.
The installed HiNC on Windows is the web service hosted this way: its host adds the installation's data folder, its self-update and a second licence source — a cloud account, signed in on a page of its own before the service starts, in place of the Sentinel key the web service uses on its own — see Installing HiNC on Windows, Updating HiNC on Windows and Signing In with a Cloud Account.
From 3.2.57 on, the installed HiNC's host also looks for a HiNC that is already running before it
decides the licence source and before it calls BuildApp: a start that finds one opens it in the
browser, where a first start would open one, and ends with exit code 0, having asked for no licence
and built no step storage.
Installing HiNC on Windows says
when a start does that and when it goes on. The web service's own Main has no such check: a second
start of one instance ends at the bind failure.
Source Code Path
See HiNC App Anatomy for git repository links.
Web Application
HiNC-2025-webservice (Quasar CLI SPA):
Program.cs— theContentRootPathandConfigureBuilderhooks, andBuildApp,AnnounceWhenStartedandRunApp, which a hosting project'sMaincalls.Execution/ExecutionStatusService.cs— the publicStatusRunningandStatusPausedconstants a hosting project compares a run's state against.wwwroot-src/quasar.config.ts— theproductalias with itsHINC_PRODUCT_SPAoverride.wwwroot-src/src/product/index.ts— the product module's exports, each the web service's own choice when it runs on its own.
See Also
- Program and Hosting — the host a project takes over: the pipeline, the services and
the shutdown a
RunAppstill runs - Configuration — the settings chain a hosting project can extend, and the content root those files are read from
- Main Panel — the menu bar whose version mark, Help items after the Log Viewer and cloud licence badge come from the product module a hosting project can replace
- Installing HiNC on Windows — the installed HiNC, this web service hosted with the installation's data folder and self-update, from the operator's side
- Updating HiNC on Windows — the update the installed host adds, which the web service on its own does not have
- Signing In with a Cloud Account — the cloud account the installed host signs in before the service starts, in place of the Sentinel key