initializeApplication static method Null safety

Future initializeApplication(
  1. ApplicationOptions options
)

You implement this method to provide global initialization for your application.

Most of your application initialization code is written in prepare, which is invoked for each isolate. For initialization that needs to occur once per application start, you must provide an implementation for this method. This method is invoked prior to any isolates being spawned.

You may alter options in this method and those changes will be available in each instance's options. To pass arbitrary data to each of your isolates at startup, add that data to ApplicationOptions.context.

Example:

    class MyChannel extends ApplicationChannel {
      static Future initializeApplication(ApplicationOptions options) async {
        options.context["runtimeOption"] = "foo";
      }

      Future prepare() async {
        if (options.context["runtimeOption"] == "foo") {
          // do something
        }
      }
    }

Do not configure objects like CodecRegistry, CORSPolicy.defaultPolicy or any other value that isn't explicitly passed through options.

  • Note that static methods are not inherited in Dart and therefore you are not overriding this method. The declaration of this method in the base ApplicationChannel class is for documentation purposes.

Implementation

static Future initializeApplication(ApplicationOptions options) async {}