| |
| |
| |
| # ComponentContext.create constructor |
| |
| |
| |
| |
| *[<Null safety>](https://dart.dev/null-safety)* |
| |
| |
| |
| ComponentContext.create() |
| |
| |
| <p>Creates the component context. Users need to make sure that they call |
| serve after they have finished adding all their public services.</p> |
| <p>Note: ComponentContext can only be constructed once.</p> |
| <p>Example:</p> |
| <pre class="language-dart"><code>Future<void> main() async { |
| final context = ComponentContext.create(); |
| ... |
| await doAsyncSetup(); |
| ... |
| context.outgoing.serveFromStartupInfo(); |
| } |
| </code></pre> |
| |
| |
| |
| ## Implementation |
| |
| ```dart |
| factory ComponentContext.create() { |
| if (_componentContext != null) { |
| throw Exception( |
| 'Attempted to construct ComponentContext multiple times. Ensure that the existing ComponentContext is reused instead of constructing multiple instances.'); |
| } |
| return _componentContext = ComponentContext( |
| svc: Platform.isFuchsia ? Incoming.fromSvcPath() : Incoming(), |
| outgoing: Outgoing(), |
| ); |
| } |
| ``` |
| |
| |
| |
| |
| |
| |
| |