[incoming] remove dirProxy from initializer

TEST=
- fx run-test fuchsia_services_package_integration_tests

Change-Id: I228343b00c2ebebc13d839b5d045dab7e34aa066
diff --git a/bin/fidl_bindings_test/test/test/server.dart b/bin/fidl_bindings_test/test/test/server.dart
index d41f90a..f61f309 100644
--- a/bin/fidl_bindings_test/test/test/server.dart
+++ b/bin/fidl_bindings_test/test/test/server.dart
@@ -5,7 +5,6 @@
 import 'dart:async';
 
 import 'package:fidl_fidl_examples_bindingstest/fidl_async.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fuchsia_services/services.dart';
 
@@ -21,16 +20,15 @@
     final launcherProxy = LauncherProxy();
     StartupContext.fromStartupInfo().incoming.connectToService(launcherProxy);
 
-    final dirProxy = DirectoryProxy();
+    final incoming = Incoming();
     final launchInfo = LaunchInfo(
-        url: _kServerName,
-        directoryRequest: dirProxy.ctrl.request().passChannel());
+        url: _kServerName, directoryRequest: incoming.request().passChannel());
     // Use the launcher services launch echo server via launchInfo
     await launcherProxy.createComponent(launchInfo, controller.ctrl.request());
     // Close connection to launcher service
     launcherProxy.ctrl.close();
 
-    Incoming(dirProxy).connectToService(proxy);
+    incoming.connectToService(proxy);
   }
 
   Future<void> stop() async {
diff --git a/bin/fidl_compatibility_test/dart/lib/main.dart b/bin/fidl_compatibility_test/dart/lib/main.dart
index efd8f15..70008cc 100644
--- a/bin/fidl_compatibility_test/dart/lib/main.dart
+++ b/bin/fidl_compatibility_test/dart/lib/main.dart
@@ -6,7 +6,6 @@
 
 import 'package:fidl/fidl.dart' show InterfaceRequest;
 import 'package:fidl_fidl_test_compatibility/fidl_async.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fuchsia_services/services.dart';
 
@@ -28,16 +27,16 @@
   Future<Struct> proxyEcho(Struct value, String forwardToServer) async {
     assert(forwardToServer.isNotEmpty);
 
-    final dirProxy = DirectoryProxy();
+    final incoming = Incoming();
     final launchInfo = LaunchInfo(
         url: forwardToServer,
-        directoryRequest: dirProxy.ctrl.request().passChannel());
+        directoryRequest: incoming.request().passChannel());
     final controller = ComponentControllerProxy();
     final launcher = LauncherProxy();
     _context.incoming.connectToService(launcher);
     await launcher.createComponent(launchInfo, controller.ctrl.request());
     final echo = EchoProxy();
-    Incoming(dirProxy).connectToService(echo);
+    incoming.connectToService(echo);
 
     return echo.echoStruct(value, '');
   }
@@ -60,16 +59,16 @@
   @override
   Future<void> echoStructNoRetVal(Struct value, String forwardToServer) async {
     if (forwardToServer != null && forwardToServer.isNotEmpty) {
-      final dirProxy = DirectoryProxy();
+      final incoming = Incoming();
       final launchInfo = LaunchInfo(
           url: forwardToServer,
-          directoryRequest: dirProxy.ctrl.request().passChannel());
+          directoryRequest: incoming.request().passChannel());
       final controller = ComponentControllerProxy();
       final launcher = LauncherProxy();
       _context.incoming.connectToService(launcher);
       await launcher.createComponent(launchInfo, controller.ctrl.request());
       final echo = EchoProxy();
-      Incoming(dirProxy).connectToService(echo);
+      incoming.connectToService(echo);
       // Keep echo around until we process the expected event.
       proxies[forwardToServer] = echo;
       echo.echoEvent.listen((Struct val) {
diff --git a/bin/flutter_screencap_test/test/flutter_screencap_test.dart b/bin/flutter_screencap_test/test/flutter_screencap_test.dart
index b9b6a25..5e7bae3 100644
--- a/bin/flutter_screencap_test/test/flutter_screencap_test.dart
+++ b/bin/flutter_screencap_test/test/flutter_screencap_test.dart
@@ -10,7 +10,6 @@
 import 'package:test/test.dart';
 
 import 'package:fidl/fidl.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fidl_fuchsia_ui_app/fidl_async.dart';
 import 'package:fidl_fuchsia_ui_policy/fidl_async.dart';
@@ -95,17 +94,15 @@
     InterfaceRequest<ComponentController> controllerRequest) async {
   final context = StartupContext.fromStartupInfo();
 
-  final directory = DirectoryProxy();
+  final incoming = Incoming();
   final launchInfo = LaunchInfo(
-      url: _testAppUrl,
-      directoryRequest: directory.ctrl.request().passChannel());
+      url: _testAppUrl, directoryRequest: incoming.request().passChannel());
   final launcher = LauncherProxy();
   context.incoming.connectToService(launcher);
   await launcher.createComponent(launchInfo, controllerRequest);
   launcher.ctrl.close();
 
   final viewProvider = ViewProviderProxy();
-  final incoming = Incoming(directory);
   try {
     incoming.connectToService(viewProvider);
     await viewProvider.createView(
diff --git a/examples/fidl/echo_client_async_dart/lib/main.dart b/examples/fidl/echo_client_async_dart/lib/main.dart
index 8076ef5..e78ea1d 100644
--- a/examples/fidl/echo_client_async_dart/lib/main.dart
+++ b/examples/fidl/echo_client_async_dart/lib/main.dart
@@ -5,7 +5,6 @@
 import 'dart:async';
 import 'package:fidl_fidl_examples_echo/fidl_async.dart' as fidl_echo;
 import 'package:fuchsia_services/services.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fuchsia/fuchsia.dart' show exit;
 
@@ -18,12 +17,12 @@
 
   final context = StartupContext.fromStartupInfo();
 
-  /// A [DirectoryProxy] who's channels will facilitate the connection between
+  /// An [Incoming] who's channels will facilitate the connection between
   /// this client component and the launched server component we're about to
   /// launch. This client component is looking for service under /in/svc/
   /// directory to connect to while the server exposes services others can
   /// connect to under /out/public directory.
-  final dirProxy = DirectoryProxy();
+  final incoming = Incoming();
 
   // Connect. The destination server is specified, and we request for it to be
   // started if it wasn't already.
@@ -31,7 +30,7 @@
     url: serverUrl,
     // The directoryRequest is the handle to the /out directory of the launched
     // component.
-    directoryRequest: dirProxy.ctrl.request().passChannel(),
+    directoryRequest: incoming.request().passChannel(),
   );
 
   // Creates a new instance of the component described by launchInfo.
@@ -49,7 +48,7 @@
   // Bind. We bind EchoProxy, a generated proxy class, to the remote Echo
   // service.
   final _echo = fidl_echo.EchoProxy();
-  Incoming(dirProxy).connectToService(_echo);
+  incoming.connectToService(_echo);
 
   // Invoke echoString with a value and print it's response.
   final response = await _echo.echoString('hello');
diff --git a/lib/xi/fuchsia_client/lib/client.dart b/lib/xi/fuchsia_client/lib/client.dart
index f3d3f3e..43da4b9 100644
--- a/lib/xi/fuchsia_client/lib/client.dart
+++ b/lib/xi/fuchsia_client/lib/client.dart
@@ -7,7 +7,6 @@
 import 'dart:typed_data';
 
 import 'package:fidl_fuchsia_ledger/fidl_async.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart' as io;
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fidl/fidl.dart';
 import 'package:fidl_fuchsia_xi/fidl_async.dart' as service;
@@ -69,7 +68,7 @@
   XiFuchsiaClient(InterfaceHandle<Ledger> _ledgerHandle) {
     // Note: _ledgerHandle is currently unused, but we're hoping to bring it back.
   }
-  final _dirProxy = io.DirectoryProxy();
+  final _incoming = Incoming();
   final service.JsonProxy _jsonProxy = service.JsonProxy();
 
   @override
@@ -88,14 +87,14 @@
     // Use the launcher services launch echo server via launchInfo
     final LaunchInfo launchInfo = LaunchInfo(
         url: 'fuchsia-pkg://fuchsia.com/xi_core#meta/xi_core.cmx',
-        directoryRequest: _dirProxy.ctrl.request().passChannel());
+        directoryRequest: _incoming.request().passChannel());
     await launcherProxy.createComponent(
         launchInfo, componentController.ctrl.request());
 
     // Close launcher connection since we no longer need the launcher service.
     launcherProxy.ctrl.close();
 
-    Incoming(_dirProxy).connectToService(_jsonProxy);
+    _incoming.connectToService(_jsonProxy);
 
     final SocketPair pair = SocketPair();
     await _jsonProxy.connectSocket(pair.first);
diff --git a/public/dart/fuchsia_services/lib/src/incoming.dart b/public/dart/fuchsia_services/lib/src/incoming.dart
index 44edaea..8178101 100644
--- a/public/dart/fuchsia_services/lib/src/incoming.dart
+++ b/public/dart/fuchsia_services/lib/src/incoming.dart
@@ -34,13 +34,16 @@
 class Incoming {
   DirectoryProxy _dirProxy;
 
+  /// Initializes [Incoming] with an unbound [DirectoryProxy] which can be used
+  /// to bind to a launched component's services.
+  Incoming() : this.withDirectory(DirectoryProxy());
+
   /// Initializes [Incoming] with a [Directory] that should be bound to `/svc`
   /// of this component.
   ///
-  /// [dir] is now optional to aid in soft transition. It will soon be removed.
-  /// If [dir] is not bound before connecting to a service an
-  /// [IncomingStateException] will be thrown
-  Incoming([DirectoryProxy dir]) : _dirProxy = dir ?? DirectoryProxy();
+  /// If you are launching a component use the [Incoming()] constructor
+  /// to get an unbound directory.
+  Incoming.withDirectory(this._dirProxy) : assert(_dirProxy != null);
 
   /// Terminates connection and return Zircon status.
   Future<int> close() async {
diff --git a/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart b/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
index 1cc21d9..f24a68f 100644
--- a/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
+++ b/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
@@ -53,26 +53,24 @@
   /// of instantiating one on their own as it will bind and connect to all the
   /// underlying services for them.
   factory StartupContextImpl.fromStartupInfo() {
-    final directoryProxy = fidl_io.DirectoryProxy();
-
     if (Directory(_serviceRootPath).existsSync()) {
       final channel = Channel.fromFile(_serviceRootPath);
-      final directoryProxy = fidl_io.DirectoryProxy()
+      final directory = fidl_io.DirectoryProxy()
         ..ctrl.bind(InterfaceHandle<fidl_io.Directory>(channel));
+      final incoming = Incoming.withDirectory(directory);
 
       // Note takeOutgoingServices shouldn't be called more than once per pid
       final outgoingServicesHandle = MxStartupInfo.takeOutgoingServices();
 
-      final incomingServices = Incoming(directoryProxy);
       return StartupContextImpl(
-        incoming: incomingServices,
+        incoming: incoming,
         outgoing: _getOutgoingFromHandle(outgoingServicesHandle),
       );
     }
 
     // The following is required to enable host side tests.
     return StartupContextImpl(
-      incoming: Incoming(directoryProxy),
+      incoming: Incoming(),
       outgoing: Outgoing(),
     );
   }
@@ -99,9 +97,9 @@
       }
     }
 
-    final dirProxy = fidl_io.DirectoryProxy();
-    dirProxy.ctrl.bind(InterfaceHandle(serviceRoot));
-    final incomingSvc = Incoming(dirProxy);
+    final dirProxy = fidl_io.DirectoryProxy()
+      ..ctrl.bind(InterfaceHandle(serviceRoot));
+    final incomingSvc = Incoming.withDirectory(dirProxy);
 
     Channel dirRequestChannel = startupInfo.launchInfo.directoryRequest;
 
diff --git a/public/dart/fuchsia_services/test/launch_flow_test.dart b/public/dart/fuchsia_services/test/launch_flow_test.dart
index ba985c9..aee7e7d 100644
--- a/public/dart/fuchsia_services/test/launch_flow_test.dart
+++ b/public/dart/fuchsia_services/test/launch_flow_test.dart
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_test_fuchsia_service_foo/fidl_async.dart';
 import 'package:fuchsia_services/services.dart';
 import 'package:test/test.dart';
@@ -13,9 +12,9 @@
 
 void main() {
   test('launching and connecting to the foo service', () async {
-    final dirProxy = DirectoryProxy();
+    final incoming = Incoming();
     final launchInfo = LaunchInfo(
-        url: server, directoryRequest: dirProxy.ctrl.request().passChannel());
+        url: server, directoryRequest: incoming.request().passChannel());
     final launcherProxy = LauncherProxy();
 
     StartupContext.fromStartupInfo().incoming.connectToService(launcherProxy);
@@ -24,7 +23,7 @@
     launcherProxy.ctrl.close();
 
     final fooProxy = FooProxy();
-    Incoming(dirProxy).connectToService(fooProxy);
+    incoming.connectToService(fooProxy);
 
     final response = await fooProxy.echo('foo');
     expect(response, 'foo');
diff --git a/public/dart/sledge/BUILD.gn b/public/dart/sledge/BUILD.gn
index 67c4ad4..02c7ace 100644
--- a/public/dart/sledge/BUILD.gn
+++ b/public/dart/sledge/BUILD.gn
@@ -134,7 +134,6 @@
     "//third_party/dart-pkg/pub/test",
     "//topaz/public/dart/fuchsia_services",
     "//topaz/public/dart/zircon",
-    "//zircon/public/fidl/fuchsia-io",
   ]
 }
 
diff --git a/public/dart/sledge/test/integration_tests/helpers.dart b/public/dart/sledge/test/integration_tests/helpers.dart
index 2625be1..c0c8233 100644
--- a/public/dart/sledge/test/integration_tests/helpers.dart
+++ b/public/dart/sledge/test/integration_tests/helpers.dart
@@ -4,7 +4,6 @@
 
 import 'dart:async';
 
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl/fidl.dart' as fidl;
 import 'package:fidl_fuchsia_ledger/fidl_async.dart' as ledger;
 import 'package:fidl_fuchsia_sys/fidl_async.dart'
@@ -32,9 +31,9 @@
   String server =
       'fuchsia-pkg://fuchsia.com/ledger_test_instance_provider#meta/ledger_test_instance_provider.cmx';
 
-  final dirProxy = DirectoryProxy();
+  final incoming = Incoming();
   final LaunchInfo launchInfo = LaunchInfo(
-      url: server, directoryRequest: dirProxy.ctrl.request().passChannel());
+      url: server, directoryRequest: incoming.request().passChannel());
   final context = StartupContext.fromStartupInfo();
   final ComponentControllerProxy controller = ComponentControllerProxy();
 
@@ -42,7 +41,7 @@
   context.incoming.connectToService(launcher);
   await launcher.createComponent(launchInfo, controller.ctrl.request());
 
-  return LedgerTestInstanceProvider(Incoming(dirProxy), controller);
+  return LedgerTestInstanceProvider(incoming, controller);
 }
 
 /// Sledge subclass that makes sure the ComponentControllerProxy does not get GCed.
diff --git a/runtime/dart_runner/integration/BUILD.gn b/runtime/dart_runner/integration/BUILD.gn
index f4e72f0..a70277a 100644
--- a/runtime/dart_runner/integration/BUILD.gn
+++ b/runtime/dart_runner/integration/BUILD.gn
@@ -48,6 +48,5 @@
     "//third_party/dart-pkg/pub/test",
     "//topaz/public/dart/fuchsia_services",
     "//topaz/runtime/dart_runner/examples/hello_app_dart/interfaces:interfaces",
-    "//zircon/public/fidl/fuchsia-io",
   ]
 }
diff --git a/runtime/dart_runner/integration/main.dart b/runtime/dart_runner/integration/main.dart
index 2a92900..f6b53af 100644
--- a/runtime/dart_runner/integration/main.dart
+++ b/runtime/dart_runner/integration/main.dart
@@ -6,7 +6,6 @@
 import 'dart:io' as io;
 
 import 'package:fidl_fuchsia_examples_hello/fidl_async.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart';
 import 'package:fuchsia_services/services.dart';
 import 'package:test/test.dart';
@@ -40,16 +39,16 @@
 
   test('communicate with a fidl service (hello_app_dart)', () async {
     final HelloProxy service = HelloProxy();
-    final dirProxy = DirectoryProxy();
+    final incoming = Incoming();
 
     final ComponentControllerProxy actl = ComponentControllerProxy();
 
     final LaunchInfo info = LaunchInfo(
         url:
             'fuchsia-pkg://fuchsia.com/hello_app_dart_jit#meta/hello_app_dart_jit.cmx',
-        directoryRequest: dirProxy.ctrl.request().passChannel());
+        directoryRequest: incoming.request().passChannel());
     await launcher.createComponent(info, actl.ctrl.request());
-    Incoming(dirProxy).connectToService(service);
+    incoming.connectToService(service);
 
     expect(await service.say('hello'), equals('hola from Dart!'));
 
diff --git a/shell/ermine/lib/src/models/app_model.dart b/shell/ermine/lib/src/models/app_model.dart
index c9d9a78..caebfad 100644
--- a/shell/ermine/lib/src/models/app_model.dart
+++ b/shell/ermine/lib/src/models/app_model.dart
@@ -4,7 +4,6 @@
 
 import 'dart:async';
 
-import 'package:fidl_fuchsia_io/fidl_async.dart';
 import 'package:fidl_fuchsia_modular/fidl_async.dart'
     show
         SessionShellContextProxy,
@@ -140,14 +139,14 @@
   }
 
   void _loadAskBar() {
-    final dirProxy = DirectoryProxy();
+    final incoming = Incoming();
     final launcherProxy = LauncherProxy();
     startupContext.incoming.connectToService(launcherProxy);
 
     launcherProxy.createComponent(
       LaunchInfo(
         url: _kErmineAskModuleUrl,
-        directoryRequest: dirProxy.ctrl.request().passChannel(),
+        directoryRequest: incoming.request().passChannel(),
         additionalServices: ServiceList(
           names: <String>[
             PuppetMaster.$serviceName,
@@ -167,7 +166,7 @@
     );
 
     final viewProvider = ViewProviderProxy();
-    Incoming(dirProxy)
+    incoming
       ..connectToService(viewProvider)
       ..connectToService(_ask)
       ..close();