Skip to Content
TAdminHosting, DI and WebApi

Hosting, DI and WebApi

On this page

Generic host entry point

Add Microsoft.Extensions.Hosting to the quick-start dependencies. The following is the Program.cs entry point; register HTTP services and controllers in the host startup class.

TUtility.Generator emits AppStartupRunner. Register services, build the container, initialize, then start:

using Microsoft.Extensions.Hosting; using TUtility; var builder = Host.CreateDefaultBuilder(args).AddJsonConfig(); builder.ConfigureServices((_, services) => AppStartupRunner.ConfigureServices(services)); using var host = builder.Build(); AppStartupRunner.Configure(host.Services); await host.RunAsync();

AdminStartup.Order is 400. Larger values run first. The sample’s SampleStartup.Order is 300, so it adds host capabilities after administration service registration. See TUtility startup.

Move the sample into your host

Use samples/TAdmin.Sample in the standalone repository as the reference, then integrate in dependency order:

StageIntegration pointExpected result
Load configurationProgram.cs, appsettings.json and ConfigurationAdministration and log databases, JWT and bootstrap settings share one configuration source; see configuration
Register services and modulesYour AppStartup.ConfigureServices, following SampleStartup.csModule, seed and route providers, RPC store, filters and HTTP hosted service are registered
Build and initializeCall AppStartupRunner.Configure(host.Services) after builder.Build()Administration initialization completes; service registration alone is insufficient
Start HTTPIHostedService.StartAsync, following Hosting/SampleWebApiService.csResolver, listener, JSON and plugins use the same service graph
Connect the frontendVue entry point and request clientPermission, session, i18n and route adapters work; see Vue integration

Share one container

The sample bridges IServiceCollection through AspNetCoreContainer, then calls BuildResolver after constructing the service provider. Controllers, authentication, the permission catalog and HTTP request scopes must use that same service graph. Creating a second provider can create independent session services or database state.

Pipeline components

Entry pointResponsibility
AuthPluginBearer validation, authentication context and near-expiry renewal
ExternalIdentityPluginExternal identity callbacks and browser protocol
ValidationFilterInput validation
AuthorizationFilterAPI permissions
UnifyResultFilterResponse envelopes and error status mapping
OperateLogFilterOperation log capture
UseWebApiRouting and JSON conversion

SampleStartup.cs registers filters in this order: ValidationFilter, AuthorizationFilter, UnifyResultFilter, OperateLogFilter. Hosting/SampleWebApiService.cs registers AuthPlugin and ExternalIdentityPlugin before UseWebApi.

Register administration and business controllers in the HTTP service’s RPC store, then publish its permission catalog with AdminApiPermissionCatalog.SetRpcStore(store). DI registration alone does not expose routes. See the module example.

JSON and integers

The sample installs SystemTextJsonSafeInt64Converter and SystemTextJsonSafeUInt64Converter in the WebApi converter and applies common JSON options and resolvers. Preserve identifiers outside JavaScript’s safe integer range instead of coercing them into number.

Lifetime

Manage HttpService through an IHostedService. Dispose the HTTP instance if startup fails. On shutdown, stop accepting requests, then flush administration log queues.

Set the HTTP body limit to accommodate valid workbooks and transport overhead while retaining decompression and business row budgets. Static page hosting remains the host’s choice; the sample uses embedded resources.

See the troubleshooting reference for routing and authentication failures.