string Environment { get; }
Gets the current environment name (e.g., "Development", "Staging", "Production").
The foundation of the Runnable ecosystem. This package defines the core abstractions, the startup pipeline, and the module system that powers all other Runnable libraries.
The Core library is designed to be lightweight and implementation-agnostic. it provides the infrastructure to:
IRunnableModule, IRunnableHostModule) that encapsulate logic.RunnableStartup) that sits on top of the .NET Generic Host.IRunnableModule: The base interface for any unit of functionality that needs to register services or configure the application.StartupContext: Provides metadata about the running application (e.g., environment, entry point assembly).RunnableStartup: The base class that orchestrates the host building and service registration process.Most users will use a more specialized package like ForgeTrust.Runnable.Web or ForgeTrust.Runnable.Console, which inherit from the abstractions provided here.
Provides a base implementation for starting and running applications with module support.
ILogger GetStartupLogger()
Provides an ILogger named after the concrete startup type.
An ILogger whose category name is the concrete startup type's name.
An abstract base class for initializing a Runnable application with a specific root module.
TRootModuleThe type of the root module for the application.Task IRunnableStartup.RunAsync(StartupContext context)
Runs the startup sequence using the provided startup context.
contextStartup configuration including application arguments, root module, and dependency/module registrations.A task that completes when the startup sequence finishes.
Task RunAsync(string[] args)
Starts the application's run sequence using the specified command-line arguments.
argsCommand-line arguments supplied to the application.A task that completes when the host run finishes.
Task RunAsync(StartupContext context)
Runs the host configured by the provided startup context and logs lifecycle events.
contextContext containing application name, root module, dependencies, and any custom registrations used to build and configure the host.A task that completes when the host run has finished and shutdown processing is complete.
Logs a warning if shutdown is cancelled or does not complete in time. On an unhandled exception logs a critical error and sets Environment.ExitCode to -100.
IHostBuilder IRunnableStartup.CreateHostBuilder(StartupContext context)
Creates an IHostBuilder configured for the provided startup context.
contextThe startup context whose application name, modules, and registrations drive host configuration.An IHostBuilder configured according to the given context.
IHost CreateHost(StartupContext context)
Builds an IHost from the host builder configured for the provided startup context.
contextThe startup context that provides application name, modules, and configuration used to construct the host.The constructed IHost.
IHostBuilder CreateHostBuilderCore(StartupContext context)
Create and configure a host builder using values from the provided startup context.
contextStartup context containing the ApplicationName, RootModule, and Dependencies used to configure the host builder.A host builder configured with the context's application name, registered modules, and service registrations.
TRootModule CreateRootModule()
Creates a new instance of the root module.
A new TRootModule instance.
void ConfigureServicesForAppType(StartupContext context, IServiceCollection services)
Registers services required for the specific application type (for example, web or worker) into the provided service collection.
contextStartup context containing application metadata, dependencies, and configuration used during registration.servicesThe service collection to which app-type-specific services should be added or overridden.IHostBuilder ConfigureBuilderForAppType(StartupContext context, IHostBuilder builder)
Allows the startup to customize the host builder for the specific application type.
contextThe startup context containing application metadata and dependency modules.builderThe host builder to customize.The configured IHostBuilder (by default returns the provided builder unchanged).
Defines the entry point for starting and running a Runnable application.
IHostBuilder CreateHostBuilder(StartupContext context)
Creates and configures the IHostBuilder for the application.
contextThe startup context containing configuration and arguments.A configured host builder.
Task RunAsync(StartupContext context)
Runs the application asynchronously using the provided startup context.
contextThe startup context for the application.A task that represents the asynchronous run operation.
Provides information about the application's environment and configuration variables.
string? GetEnvironmentVariable(string name, string? defaultValue = null)
Gets the value of an environment variable.
nameThe name of the environment variable.defaultValueThe value to return if the environment variable is not set.The value of the environment variable, or the default value if not found.
string Environment { get; }
Gets the current environment name (e.g., "Development", "Staging", "Production").
bool IsDevelopment { get; }
Gets a value indicating whether the current environment is "Development".
Provides context and configuration during the application startup process.
ArgsCommand-line arguments provided to the application.RootModuleThe root module of the application.ApplicationNameOptional name of the application.EnvironmentProviderOptional provider for environment information.CustomRegistrationsOptional custom service registrations.IReadOnlyList<IRunnableModule> GetDependencies()
Gets the list of modules that the application depends on.
A read-only list of dependent modules.
Assembly? OverrideEntryPointAssembly { get; set; }
Gets or sets an assembly that should be treated as the entry point assembly, overriding the default.
Assembly RootModuleAssembly { get; }
Gets the assembly that contains the root module.
Assembly EntryPointAssembly { get; }
Gets the entry point assembly for the application.
IEnvironmentProvider EnvironmentProvider { get; }
Gets the environment provider for the application.
bool IsDevelopment { get; }
Gets a value indicating whether the current environment is development.
string ApplicationName { get; }
Gets the name of the application.
A builder used to discover and register module dependencies recursively.
ModuleDependencyBuilder AddModule<T>()
Adds a module of type T and its dependencies to the builder.
TThe type of the module to add.The current ModuleDependencyBuilder instance.
IEnumerable<IRunnableModule> Modules { get; }
Gets the collection of registered modules.
A base class for background services that are critical to the application's operation. If a critical service fails or exits, the entire application will be shut down.
Task RunAsync(CancellationToken stoppingToken)
Implements the core logic of the critical service.
stoppingTokenA token that is signaled when the service should stop.A task that represents the service's execution.
void LogInitialize(string serviceType)
Logs that the critical service is initializing.
serviceTypeThe name of the service type.void LogStopping(string serviceType)
Logs that the critical service is stopping.
serviceTypeThe name of the service type.void LogException(Exception exception, string serviceType)
Logs an unhandled exception that occurred in the critical service.
exceptionThe unhandled exception.serviceTypeThe name of the service type.Defines a module that can configure services and register dependencies within the Runnable host.
void ConfigureServices(StartupContext context, IServiceCollection services)
Configures the services for this module.
contextThe context for the current startup process.servicesThe service collection to add registrations to.void RegisterDependentModules(ModuleDependencyBuilder builder)
Registers other modules that this module depends on.
builderThe builder used to declare module dependencies.Defines a module that can specifically configure the IHostBuilder before and after service registration. Only the root module of an application (or explicitly marked host modules) usually implements this.
void ConfigureHostBeforeServices(StartupContext context, IHostBuilder builder)
Configures the IHostBuilder before any modules have their services configured.
contextThe context for the current startup process.builderThe host builder to configure.void ConfigureHostAfterServices(StartupContext context, IHostBuilder builder)
Configures the IHostBuilder after all modules have their services configured.
contextThe context for the current startup process.builderThe host builder to configure.Provides utility methods for operations on file and directory paths.
string FindRepositoryRoot(string startPath)
Locates the nearest ancestor directory (starting at startPath) that contains a `.git` directory or file, effectively identifying the repository root.
startPathThe path from which to begin searching upward for a repository root; may refer to a file or directory.The full path of the nearest ancestor directory containing a `.git` directory or file, or the original startPath if none is found.
ArgumentExceptionThrown when startPath is null, empty, or consists only of whitespace.