Skip to content

Commit

Permalink
fix: new bind overwrites the previus one (ModuleContainer)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Apr 3, 2018
1 parent 03ec3fc commit 357dcbd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/src/injector.dart
Expand Up @@ -34,9 +34,9 @@ abstract class Injector {
var injector = new InjectorImpl();
injectors.forEach((ijtor) =>
ijtor.registrations.forEach((typeMirrorWrapper, registration) {
if (!injector._registrations.containsKey(typeMirrorWrapper)) {
//if (!injector._registrations.containsKey(typeMirrorWrapper)) {
injector._registrations[typeMirrorWrapper] = registration;
}
//}
})
);
return injector;
Expand Down
27 changes: 24 additions & 3 deletions lib/src/module.dart
Expand Up @@ -47,20 +47,41 @@ abstract class Module {
_registrations[new TypeMirrorWrapper(type, name, annotation)];

final Map<TypeMirrorWrapper, Registration> _registrations = new Map<TypeMirrorWrapper, Registration>();

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Module &&
runtimeType == other.runtimeType &&
_registrations == other._registrations;

@override
int get hashCode => _registrations.hashCode;
}

/// Combines several [Module] into single one, allowing to inject
/// a class from one module into a class from another module.
class _ModuleContainer extends Module {
final List<Module> _modules;

_ModuleContainer(List<Module> this._modules);

@override
configure() {
_modules.fold(_registrations, (acc, module) {
_registrations.clear();
_modules.forEach((final Module module) {
module.configure();
return acc..addAll(module._registrations);
module._registrations.forEach((final TypeMirrorWrapper tm, final Registration registration) {
_registrations[tm] = registration;
});
});

// Old version (reminder)
// _modules.fold(_registrations, (final acc,final Module module) {
// module.configure();
// return acc..addAll(module._registrations);
// });

}

List<Module> _modules;
}

0 comments on commit 357dcbd

Please sign in to comment.