Permalink
Browse files

feature: IOC-Container can register Events

  • Loading branch information...
MikeMitterer committed Nov 19, 2018
1 parent 7e1fc07 commit 1b090bf46bf60ac351ea5d2cbd5612cce11b9a6d
Showing with 20 additions and 0 deletions.
  1. +20 −0 lib/m4d_ioc.dart
@@ -22,6 +22,7 @@ library m4d_ioc;
import 'package:validate/validate.dart';

typedef Map<String, dynamic> ToJson();
typedef Map<String, Function> ToEvents();

abstract class Binder {
void bind();
@@ -118,6 +119,8 @@ class BindingSyntax {

void toJson(ToJson callback) => _JsonBinder(_service, callback).bind();

void toEvents(ToEvents callback) => _EventsBinder(_service, callback).bind();

BindingSyntax._private(this._service);
}

@@ -185,3 +188,20 @@ class _JsonBinder extends Binder {
}
}

class _EventsBinder extends Binder {
final Service _service;
final ToEvents _callback;

_EventsBinder(this._service,this._callback);

@override
void bind() {
Validate.notNull(_service);
Validate.notNull(_callback);
Validate.isTrue(_service.type == ServiceType.Function);
Validate.isTrue(_callback is ToEvents);

IOCContainer()._services[_service] = _callback;
}
}

0 comments on commit 1b090bf

Please sign in to comment.