MvcOptions Mvc { get; set; }
Gets or sets MVC-specific configuration options, such as support levels and custom MVC configuration.
The ForgeTrust.Runnable.Web package provides the bootstrapping logic for building ASP.NET Core applications using the Runnable module system. It sits on top of the compilation concepts defined in ForgeTrust.Runnable.Core.
The easiest way to get started is by using the WebApp static entry point. This provides a default setup that works for most applications.
await WebApp<MyRootModule>.RunAsync(args);
For more advanced use cases where you need to customize the startup lifecycle beyond what the options provide, you can extend WebStartup<TModule>.
WebAppThe primary entry point for web applications. It handles creating the internal startup class and running the application. It provides a generic overload WebApp<TModule> for standard usage and WebApp<TStartup, TModule> if you have a custom startup class.
IRunnableWebModuleModules that want to participate in the web startup lifecycle should implement this interface. It extends IRunnableHostModule and adds web-specific hooks:
ConfigureWebOptions: Modify the global WebOptions (e.g., enable MVC, configure CORS).ConfigureWebApplication: Register middleware using IApplicationBuilder (e.g., app.UseAuthentication()).ConfigureEndpoints: Map endpoints using IEndpointRouteBuilder (e.g., endpoints.MapGet("/", ...)).WebStartupThe base class for the application bootstrapping logic. While WebApp uses a generic version of this internally, you can extend it if you need deep customization of the host builder or service configuration logic.
Support for MVC approaches can be configured via WebOptions:
AddControllers).Built-in support for CORS configuration:
EnableCors is true, you MUST specify at least one origin in AllowedOrigins, unless running in Development with EnableAllOriginsInDevelopment enabled (the default). If AllowedOrigins is empty in production or when EnableAllOriginsInDevelopment is disabled, the application will throw a startup exception to prevent unintended security openness (verified by tests EmptyOrigins_WithEnableCors_ThrowsException and EnableAllOriginsInDevelopment_AllowsAnyOrigin).EnableAllOriginsInDevelopment (enabled by default) automatically allows any origin when the environment is Development, simplifying local testing without compromising production security.Modules can define their own endpoints, making it easy to slice features vertically ("Vertical Slice Architecture").
The web application supports standard ASP.NET Core configuration sources (command-line arguments, environment variables, and appsettings.json).
You can override the application's listening port using several methods:
--port (shortcut) or --urls.
dotnet run -- --port 5001
# OR
dotnet run -- --urls "http://localhost:5001"
ASPNETCORE_URLS.
export ASPNETCORE_URLS="http://localhost:5001"
dotnet run
urls in appsettings.json.
{
"urls": "http://localhost:5001"
}
Note
The --port flag is a convenience shortcut that maps to http://localhost:{port};http://*:{port}. This ensures the application is accessible on all interfaces while logging a clickable localhost URL in the console. If both --port and --urls are provided, --port takes precedence.
Represents configuration options for the web application, including MVC, CORS, and static file settings.
MvcOptions Mvc { get; set; }
Gets or sets MVC-specific configuration options, such as support levels and custom MVC configuration.
CorsOptions Cors { get; set; }
Gets or sets CORS configuration options for defining cross-origin resource sharing policies.
StaticFilesOptions StaticFiles { get; set; }
Gets or sets configuration options for serving static files within the web application.
Action<IEndpointRouteBuilder>? MapEndpoints { get; set; }
Gets or sets an optional delegate to configure endpoint routing for the application.
Provides a static entry point for starting a web application with a custom startup class and root module.
TStartupThe type of the custom startup class, inheriting from WebStartup{TModule}.TModuleThe type of the root web module.Task RunAsync(string[] args, Action<WebOptions>? configureOptions = null)
Asynchronously runs the web application using the specified command-line arguments and optional option configuration.
argsThe command-line arguments provided at application startup.configureOptionsAn optional delegate to further customize WebOptions during startup.A Task representing the asynchronous operation of running the web application.
Provides a simplified static entry point for starting a web application using a default startup configuration.
TModuleThe type of the root web module.Task RunAsync(string[] args, Action<WebOptions>? configureOptions = null)
Asynchronously runs the web application with a default startup using the specified command-line arguments and optional configuration.
argsThe command-line arguments provided at application startup.configureOptionsAn optional delegate to customize WebOptions during startup.A Task representing the asynchronous operation of running the web application.
Represents configuration options for ASP.NET Core MVC services and features.
MvcOptions Default { get; }
Gets a new default instance of MvcOptions configured with MvcSupport.Controllers.
MvcSupport MvcSupportLevel { get; init; }
Gets the level of MVC support to register (e.g., Controllers only, or Controllers with Views).
Action<IMvcBuilder>? ConfigureMvc { get; init; }
Gets an optional delegate for performing advanced configuration of the IMvcBuilder.
Specifies the level of MVC feature support to enable in the web application.
Represents configuration options for Cross-Origin Resource Sharing (CORS) policies.
bool EnableAllOriginsInDevelopment { get; set; }
Gets or sets a value indicating whether all origins are allowed when running in the development environment. Defaults to true.
bool EnableCors { get; set; }
Gets or sets a value indicating whether CORS is enabled for the application. Defaults to false.
string[] AllowedOrigins { get; set; }
Gets or sets the collection of origins permitted to make cross-origin requests. Defaults to an empty array.
string PolicyName { get; set; }
Gets or sets the name of the CORS policy to register. Defaults to "DefaultCorsPolicy".
CorsOptions Default { get; }
Gets a default instance of CorsOptions with default configuration settings.
Represents configuration options for serving static files and web assets.
StaticFilesOptions Default { get; }
Gets a default instance of StaticFilesOptions with default configuration settings.
bool EnableStaticFiles { get; set; }
Gets or sets a value indicating whether static files are enabled. This is automatically enabled when MvcSupport.ControllersWithViews or higher is used.
bool EnableStaticWebAssets { get; set; }
Gets or sets a value indicating whether static web assets (from RCLs) are enabled. This is automatically enabled in the development environment.
Provides a base implementation for a web-based RunnableStartup{TModule} that handles MVC, CORS, and static file configuration based on registered IRunnableWebModule instances.
TModuleThe root IRunnableWebModule for the application.WebStartup<TModule> WithOptions(Action<WebOptions>? configureOptions = null)
Registers an optional callback to customize WebOptions and enables fluent chaining.
configureOptionsAn optional action invoked later when WebOptions are built to modify configuration.The same WebStartup{TModule} instance to support fluent configuration.
void BuildModules(StartupContext context)
Collects and caches all IRunnableWebModule instances found in the provided startup context. This method is idempotent.
contextThe startup context whose dependencies and root module are inspected for web modules.This method is idempotent; subsequent calls have no effect once modules are built.
void BuildWebOptions(StartupContext context)
Initializes and caches WebOptions by applying configuration from discovered modules and the optional custom callback; enables static file support when MVC is configured for controllers with views.
contextThe startup context used when invoking module and custom option configuration.This method is idempotent; subsequent calls have no effect once options are built.
void ConfigureServicesForAppType(StartupContext context, IServiceCollection services)
Configures services required for the web application: registers MVC application parts from the entry assembly and enabled web modules, and adds a CORS policy when CORS is enabled.
contextStartup context providing environment information and the entry-point assembly.servicesThe service collection to register MVC and CORS services into.InvalidOperationExceptionThrown when CORS is enabled but no allowed origins are specified, except when all origins are explicitly allowed in development.IHostBuilder ConfigureBuilderForAppType(StartupContext context, IHostBuilder builder)
Configures the provided host builder with web host defaults and registers the application's web initialization pipeline.
contextThe startup context used to collect modules and build web options.builderThe host builder to configure.The same IHostBuilder configured with web host defaults and the application's initialization pipeline.
void InitializeWebApplication(StartupContext context, IApplicationBuilder app)
Configures the application's middleware pipeline and endpoint routing for the web application.
contextThe startup context containing environment, entry point, and discovered modules used during configuration.appThe application builder to configure (middleware, routing, CORS, endpoints, etc.).Defines a module that exposes web-specific configuration, endpoints, and middleware.
void ConfigureWebOptions(StartupContext context, WebOptions options)
Configures WebOptions for the application, such as MVC, CORS, and static files.
contextThe startup context for the application.optionsThe options to be configured.void ConfigureEndpoints(StartupContext context, IEndpointRouteBuilder endpoints)
Allows the module to configure endpoint routes for the application.
contextStartup context providing environment and configuration for the module.endpointsEndpoint route builder used to map endpoints (routes, hubs, etc.).void ConfigureWebApplication(StartupContext context, IApplicationBuilder app)
Configure the ASP.NET Core request pipeline for this module.
contextStartup information and services available to the module during application initialization.appThe application's request pipeline builder used to register middleware, routing, and other pipeline components.bool IncludeAsApplicationPart { get; }
Gets a value indicating whether this module's assembly should be searched for MVC application parts (controllers, views, etc.). Defaults to false.