Application class
The application: a Container plus lifecycle and the loaded config.
One application per process. Global helpers (app, config, env,
route — see their respective files) and Log's static state all
resolve against Application.current, the most recently created
application (spec §5.2). Creating a second Application in the same
process redirects every one of those helpers to it, even for requests
still being served by the first application's HttpKernel — e.g. Cors
reading config('cors') mid-request would pick up the second app's
config. This is the intended contract, not a bug: tests and any other
code that builds multiple applications in one process must not
interleave requests between them.
Properties
- basePath → String
-
final
- config → Config
-
final
- debug → bool
-
no setter
- env → Env
-
final
- environment → String
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
providers
→ List<
ServiceProvider> -
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind<
T extends Object> (T factory(Container container)) → void -
Register a factory that runs on every make.
inherited
-
has<
T extends Object> () → bool -
inherited
-
instance<
T extends Object> (T value) → void -
Register an already-built object as the shared instance for
T.inherited -
make<
T extends Object> () → T -
Resolve
T. Throws BindingResolutionException when unbound.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
path(
String relative) → String - Absolute path for a path relative to basePath.
-
serve(
{String host = '0.0.0.0', int port = 8000, }) → Future< HttpServer> - Serve HTTP. Direct servers bind exclusively unless a worker coordinator explicitly enables port sharing.
-
shutdown(
{bool force = false}) → Future< void> - Stop accepting requests, wait for active requests, then release providers.
-
singleton<
T extends Object> (T factory(Container container)) → void -
Register a factory whose first result is reused for every later make.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
waitForShutdownSignal(
) → Future< void> - Keep the process alive until SIGINT/SIGTERM, then shut down gracefully.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- current → Application
-
The most recently created application — see the class doc comment for
the one-application-per-process contract this implies.
no setter
Static Methods
-
configure(
{required String basePath, Map< String, String> ? environment}) → ApplicationBuilder -
Start building an application. Loads
.envimmediately so thatenv()works inside config files evaluated bywithConfig. -
reset(
) → void - Forget the current instance (tests only).
-
serveWorkers(
Future< Application> bootstrap(), {String host = '0.0.0.0', int port = 8000, int workers = 1}) → Future<ApplicationWorkers> -
Boot
workersisolated applications sharing one HTTP port.