Permalink
Browse files

feature: Added helper function to convert a service to a string (serv…

…iceAsString)
  • Loading branch information...
MikeMitterer committed Jan 31, 2019
1 parent a8f7bda commit 2f2715afc7d684fca7b208b365a0785314496af8
Showing with 36 additions and 1 deletion.
  1. +19 −0 lib/m4d_ioc.dart
  2. +17 −1 test/unit/ioc/IOCContainer_test.dart
@@ -203,6 +203,25 @@ class ContainerResolveSyntax {
dynamic get untyped => _data;
}

/// Helper to resolves String-Service as String
///
/// E.g. Used to resolve URLs
///
/// const MyFancyURL = Service<AsString>("test.unit.ioccontainer",ServiceType.Function);
///
/// bind(MyFancyURL)
/// .toFunction<String>(() => "http://www.myhost.at/api/v1/jobs");
///
/// String get _myUrl => serviceAsString(MyFancyURL);
String serviceAsString(final Service<AsString> service) {
final function = service.resolve();
if(function == null) {
return "${service.name}:undefined";
}
return function();
}


class _InstanceBinder extends Binder {
final Service _service;
final Object _implementation;
@@ -268,7 +268,23 @@ main() async {
//final testclass = con

}); // end of 'Module with depenency' test

}); // End of '' group

group("Tools", () {
setUp(() {});
tearDown(() {
container.clear();
});

test('> Resolve Service as String', () {
const url = "http://www.myhost.at/api/v1/jobs";
const MyFancyURL = Service<AsString>("test.unit.ioccontainer",ServiceType.Function);

container.bind(MyFancyURL).toFunction<String>(() => url);

expect(serviceAsString(MyFancyURL), url);
});

});
}

0 comments on commit 2f2715a

Please sign in to comment.