Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 6b5dd1f

Browse files
committed
Replaced Manager.getFromInjector() by Manager.getInjector() and Manager.createInjector()
1 parent af4fa61 commit 6b5dd1f

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## v0.5.13
22
* Improved plugin API:
3-
* Added the `Manager.getFromInjector()` method, which allows plugins to retrieve objects from di modules more easily.
3+
* Added the `Manager.getInjector()` and `Manager.createInjector()` methods, which allow plugins to retrieve objects from di modules more easily.
44
* Added the `Manager.findFunctions()`, `Manager.findClasses()` and `Manager.findMethods()` methods, which allow plugins to scan imported libraries.
55
* Added the `Manager.getShelfHandler()` and `Manager.setShelfHandler()` methods, which allow plugins to access and replace the current installed shelf handler.
66

lib/server.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,16 @@ abstract class Manager {
560560

561561
///Set or replace the current installed shelf handler
562562
void setShelfHandler(shelf.Handler handler);
563-
564-
///Retrieve an object from the DI Injector
565-
Object getFromInjector(Type type, [Type annotation]);
563+
564+
/**
565+
* Create a new DI injector restricted to the scope of this plugin.
566+
*
567+
* The returned injector will be a child of the application injector.
568+
*/
569+
Injector createInjector(List<Module> modules);
570+
571+
///Retrieve the application DI injector
572+
Injector getInjector();
566573

567574
///Find all functions annotated with [annotation]
568575
Iterable<AnnotatedType<MethodMirror>> findFunctions(Type annotation);

lib/src/plugin_impl.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ class _ManagerImpl implements Manager {
151151
}
152152

153153
@override
154-
Object getFromInjector(Type type, [Type annotation]) =>
155-
_injector.get(type, annotation);
154+
Injector createInjector(List<Module> modules) {
155+
return new ModuleInjector(modules, _injector);
156+
}
157+
158+
@override
159+
Object getInjector() => _injector;
156160

157161
@override
158162
Iterable<AnnotatedType<MethodMirror>> findFunctions(Type annotation) {

lib/src/setup_impl.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ void _scanHandlers([List<Symbol> libraries]) {
384384
}
385385

386386
_configureGroup(manager.serverMetadata, g.metadata,
387-
g.clazz, _injector,
388-
levelHist, urlPrefix: g.lib.conf.urlPrefix);
387+
g.clazz, levelHist, urlPrefix: g.lib.conf.urlPrefix);
389388
});
390389

391390

@@ -459,15 +458,15 @@ void _clearHandlers() {
459458
}
460459

461460
void _configureGroup(_ServerMetadataImpl serverMetadata,
462-
Group group, ClassMirror clazz, Injector injector,
461+
Group group, ClassMirror clazz,
463462
List<int> chainIdxByLevel, {String urlPrefix}) {
464463

465464
var className = MirrorSystem.getName(clazz.qualifiedName);
466465
_logger.info("Found group: $className");
467466

468467
InstanceMirror instance = null;
469468
try {
470-
instance = reflect(injector.get(clazz.reflectedType));
469+
instance = reflect(_injector.get(clazz.reflectedType));
471470
} catch(e) {
472471
_logger.severe("Failed to get $className", e);
473472
throw new SetupException(className, "Failed to create a instance of the group $className");

0 commit comments

Comments
 (0)