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() {
|
||||
// Create a container instance.
|
||||
var container = new Container(MirrorsReflector());
|
||||
var container = new Container(const MirrorsReflector());
|
||||
|
||||
// Register a singleton.
|
||||
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.
|
||||
container.registerFactory<Truck>((container) {
|
||||
return _TruckImpl(container.make<Engine>());
|
||||
|
|
|
@ -23,7 +23,7 @@ class ReflectorLibraryGenerator {
|
|||
// Generate a ReflectedClass for each type
|
||||
for (var type in annotation.types) {
|
||||
if (type is InterfaceType) {
|
||||
lib.body.add(generateReflectedClass(type, lib));
|
||||
lib.body.add(generateReflectedClass(type));
|
||||
} else {
|
||||
// TODO: Handle these
|
||||
}
|
||||
|
@ -61,19 +61,13 @@ class ReflectorLibraryGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
Class generateReflectedClass(InterfaceType type, LibraryBuilder lib) {
|
||||
Class generateReflectedClass(InterfaceType type) {
|
||||
return new Class((clazz) {
|
||||
var rc = new ReCase(type.name);
|
||||
clazz
|
||||
..name = '_Reflected${rc.pascalCase}Class'
|
||||
..name = '_Reflected${rc.pascalCase}'
|
||||
..extend = refer('ReflectedClass');
|
||||
|
||||
// Create const instance
|
||||
lib.body.add(refer(clazz.name)
|
||||
.constInstanceNamed('_', [])
|
||||
.assignVar('_reflected${rc.pascalCase}Class', refer('ReflectedClass'))
|
||||
.statement);
|
||||
|
||||
// Add const constructor
|
||||
var superArgs = <Expression>[
|
||||
literalString(type.name), // name
|
||||
|
|
Loading…
Reference in a new issue