Using-Plug-ins

Using Plug-ins

Angel is designed to be extensible. As such, it exposes a typedef, AngelConfigurer, that has special privileges within the framework - they act as plug-ins and can be called via app.configure().

Plug-ins simply need to accept an Angel instance as a parameter, and return a Future (the result of which will be ignored, unless it throws an error). Angel instances have several facilities available to be customized, and thus it is easy to use a custom plug-in to bring about desired functionality within your application.

  1. typedef Future AngelConfigurer(Angel app);

As a convention, Angel plug-ins should be hooked up before the call to startServer.

  1. import 'dart:io';
  2. import 'package:angel_framework/angel_framework';
  3. plugin(Angel app) async {
  4. print("Do stuff here");
  5. }
  6. main() async {
  7. Angel app = new Angel();
  8. await app.configure(plugin);
  9. await app.startServer();
  10. }

Execution Order

Plugins are usually immediately invoked by app.configure(). However, you may run into certain plug-insthat depend on other facilities already being available, or all of your services already being mounted. You can set aside a plug-in to be run just before server startupby adding it to app.startupHooks, instead of directly calling app.configure().

  1. app.startupHooks.addAll([
  2. myPlugin(),
  3. AngelWebSocket().configureServer,
  4. fooBarBazQuux()
  5. ]);

Likewise, you can add hooks that run just before the app is shutdown, via Angel.shutdownHooks.

Next Up…

Learn how to generate content for clients by rendering views.