-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture and Request Lifecycle
Imp is one terminal ASP.NET Core middleware component with four main responsibilities:
- Resolve a request path to a page type.
- Construct that page with ASP.NET Core dependency injection.
- bind request state and run lifecycle hooks.
- Render a cached embedded template or call the page directly.
| Component | Responsibility |
|---|---|
UseImp |
Creates ImpConfiguration and registers ImpMiddleware. |
ImpMiddleware |
Coordinates routing, authentication, lifecycle, postbacks, compilation, and rendering. |
Request |
Converts a path into a page type and binds query properties. |
BasePage |
Base class containing Request, PreRender, and direct Render. |
ResourceTemplateManager |
Loads embedded page/layout resources from the configured assembly. |
PageCompiler |
Converts XML template commands into cached static/dynamic chunks. |
For every request reaching Imp:
- Imp sets the response content type to
text/htmland initially sets status 200. -
Requestderives a page type name from the path. - If the type is missing,
OnNotFoundmay return a custom page type; otherwise the configured or built-in 404 page is used. - The page is constructed with
ActivatorUtilitiesusingHttpContext.RequestServices. -
BasePage.Requestis assigned and supported query values are bound to matching properties. - If the page has
[SecurePage]and anAuthenticatecallback is configured, the callback runs. Returningfalsestops the request. - The global
OnPreRendercallback runs. - The page's
PreRendermethod runs. - For
POST, Imp invokesIAsyncPostable.PostbackAsyncorIPostable.Postback. - A
[PageTemplate]resource is compiled once per page type and rendered; without the attribute,BasePage.Renderruns.
The order matters. A postback occurs after both pre-render callbacks, and the resulting page is rendered afterward. Design validation messages and response status changes accordingly.
Compiled templates are held in a process-wide concurrent dictionary keyed by page type. Static XML is parsed and reflected once, while dynamic methods execute for every render. Changes to embedded templates require rebuilding and restarting the application.
The configured fallback not-found page is also cached by the current implementation. Keep that page stateless: do not inject scoped services into it or depend on request-specific constructor state. Data-driven fallback pages returned by OnNotFound are constructed normally for each request.
Imp does not call the next middleware delegate. A typical pipeline is:
app.UseExceptionHandler("/error");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseImp(/* configuration */);Do not place static files or authentication after UseImp; they will not see requests handled by it. If the application mixes endpoint routing and Imp, branch the pipeline or map endpoints before the terminal Imp branch deliberately.
Imp is not an ORM, model binder for request bodies, authentication system, authorization policy engine, HTML sanitizer, validation framework, or client-side UI library. Use ordinary ASP.NET Core/application services for those responsibilities.
Imp is MIT licensed. See the source and Todo sample on GitHub.
Imp
Templates
Application integration
- Forms and antiforgery
- Dependency injection
- Authentication and secure pages
- Static assets and CDN paths
- Configuration reference
Help and reference