Add mountController + test
This commit is contained in:
parent
76532f9509
commit
10b6011aba
4 changed files with 21 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
# 2.0.0-alpha.11
|
# 2.0.0-alpha.11
|
||||||
* Add `readMany` to `Service`.
|
* Add `readMany` to `Service`.
|
||||||
* Allow `ResponseContext.redirect` to take a `Uri`.
|
* Allow `ResponseContext.redirect` to take a `Uri`.
|
||||||
|
* Add `Angel.mountController`.
|
||||||
|
|
||||||
# 2.0.0-alpha.10
|
# 2.0.0-alpha.10
|
||||||
* All calls to `Service.parseId` are now affixed with the `<Id>` argument.
|
* All calls to `Service.parseId` are now affixed with the `<Id>` argument.
|
||||||
|
|
|
@ -30,7 +30,9 @@ class Controller {
|
||||||
_app = app;
|
_app = app;
|
||||||
|
|
||||||
if (injectSingleton != false) {
|
if (injectSingleton != false) {
|
||||||
_app.container.registerSingleton(this, as: runtimeType);
|
if (!app.container.has(runtimeType)) {
|
||||||
|
_app.container.registerSingleton(this, as: runtimeType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load global expose decl
|
// Load global expose decl
|
||||||
|
|
|
@ -333,6 +333,16 @@ class Angel extends Routable {
|
||||||
return new Future.sync(() => configurer(this));
|
return new Future.sync(() => configurer(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shorthand for using the [container] to instantiate, and then mount a [Controller].
|
||||||
|
///
|
||||||
|
/// Just like [Container].make, in contexts without properly-reified generics (dev releases of Dart 2),
|
||||||
|
/// provide a [type] argument as well.
|
||||||
|
///
|
||||||
|
/// If you are on `Dart >=2.0.0`, simply call `mountController<T>()`..
|
||||||
|
Future mountController<T extends Controller>([Type type]) {
|
||||||
|
return configure(container.make<T>(type).configureServer);
|
||||||
|
}
|
||||||
|
|
||||||
/// Shorthand for calling `all('*', handler)`.
|
/// Shorthand for calling `all('*', handler)`.
|
||||||
Route<RequestHandler> fallback(RequestHandler handler) {
|
Route<RequestHandler> fallback(RequestHandler handler) {
|
||||||
return all('*', handler);
|
return all('*', handler);
|
||||||
|
|
|
@ -59,7 +59,13 @@ main() {
|
||||||
"/redirect",
|
"/redirect",
|
||||||
(req, res) async =>
|
(req, res) async =>
|
||||||
res.redirectToAction("TodoController@foo", {"foo": "world"}));
|
res.redirectToAction("TodoController@foo", {"foo": "world"}));
|
||||||
await app.configure((ctrl = new TodoController()).configureServer);
|
|
||||||
|
// Register as a singleton, just for the purpose of this test
|
||||||
|
if (!app.container.has<TodoController>())
|
||||||
|
app.container.registerSingleton(ctrl = new TodoController());
|
||||||
|
|
||||||
|
// Using mountController<T>();
|
||||||
|
await app.mountController<TodoController>();
|
||||||
|
|
||||||
print(app.controllers);
|
print(app.controllers);
|
||||||
app.dumpTree();
|
app.dumpTree();
|
||||||
|
|
Loading…
Reference in a new issue