Example patch
This commit is contained in:
parent
97474294c5
commit
25065975cf
2 changed files with 9 additions and 10 deletions
|
@ -3,11 +3,16 @@ import 'package:angel_container/mirrors.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Create a container instance.
|
// Create a container instance.
|
||||||
var container = new Container(MirrorsReflector());
|
var container = new Container(const MirrorsReflector());
|
||||||
|
|
||||||
// Register a singleton.
|
// Register a singleton.
|
||||||
container.registerSingleton<Engine>(Engine(40));
|
container.registerSingleton<Engine>(Engine(40));
|
||||||
|
|
||||||
|
// You can also omit the type annotation, in which the object's runtime type will be used.
|
||||||
|
// If you're injecting an abstract class, prefer the type annotation.
|
||||||
|
//
|
||||||
|
// container.registerSingleton(Engine(40));
|
||||||
|
|
||||||
// Register a factory that creates a truck.
|
// Register a factory that creates a truck.
|
||||||
container.registerFactory<Truck>((container) {
|
container.registerFactory<Truck>((container) {
|
||||||
return _TruckImpl(container.make<Engine>());
|
return _TruckImpl(container.make<Engine>());
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ReflectorLibraryGenerator {
|
||||||
// Generate a ReflectedClass for each type
|
// Generate a ReflectedClass for each type
|
||||||
for (var type in annotation.types) {
|
for (var type in annotation.types) {
|
||||||
if (type is InterfaceType) {
|
if (type is InterfaceType) {
|
||||||
lib.body.add(generateReflectedClass(type, lib));
|
lib.body.add(generateReflectedClass(type));
|
||||||
} else {
|
} else {
|
||||||
// TODO: Handle these
|
// TODO: Handle these
|
||||||
}
|
}
|
||||||
|
@ -61,19 +61,13 @@ class ReflectorLibraryGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Class generateReflectedClass(InterfaceType type, LibraryBuilder lib) {
|
Class generateReflectedClass(InterfaceType type) {
|
||||||
return new Class((clazz) {
|
return new Class((clazz) {
|
||||||
var rc = new ReCase(type.name);
|
var rc = new ReCase(type.name);
|
||||||
clazz
|
clazz
|
||||||
..name = '_Reflected${rc.pascalCase}Class'
|
..name = '_Reflected${rc.pascalCase}'
|
||||||
..extend = refer('ReflectedClass');
|
..extend = refer('ReflectedClass');
|
||||||
|
|
||||||
// Create const instance
|
|
||||||
lib.body.add(refer(clazz.name)
|
|
||||||
.constInstanceNamed('_', [])
|
|
||||||
.assignVar('_reflected${rc.pascalCase}Class', refer('ReflectedClass'))
|
|
||||||
.statement);
|
|
||||||
|
|
||||||
// Add const constructor
|
// Add const constructor
|
||||||
var superArgs = <Expression>[
|
var superArgs = <Expression>[
|
||||||
literalString(type.name), // name
|
literalString(type.name), // name
|
||||||
|
|
Loading…
Reference in a new issue