platform/experiment/container/example2/bin/example3_controller.dart

73 lines
1.7 KiB
Dart
Raw Normal View History

2023-03-11 04:44:22 +00:00
import 'package:angel3_container_generator/angel3_container_generator.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'example3_controller.reflectable.dart';
@contained
@Expose('/controller', method: 'GET')
class MyController extends Controller {
@Expose('/')
Order order(Order singleton) => singleton;
//Todo todo(Todo singleton) => singleton;
}
class Todo extends Model {
String? text;
String? over;
Todo({this.text, this.over});
Map<String, dynamic> toJson() {
return {
'text': text,
'over': over,
};
}
}
class FoodItem {
final String name;
final num price;
2023-04-21 06:25:54 +00:00
final num qty;
2023-03-11 04:44:22 +00:00
2023-04-21 06:25:54 +00:00
FoodItem(this.name, this.price, this.qty);
2023-03-11 04:44:22 +00:00
}
class Order {
FoodItem item;
String? get name => item.name;
Order(this.item);
}
void main() async {
//var reflector = const GeneratedReflector();
//Container container = Container(reflector);
//container.registerSingleton<SalesController>(SalesController());
2023-04-15 01:07:24 +00:00
// Using GeneratedReflector
2023-03-11 04:44:22 +00:00
initializeReflectable();
var app = Angel(reflector: GeneratedReflector());
// Using MirrorReflector
//var app = Angel(reflector: MirrorsReflector());
//await app.configure(MyController().configureServer);
// My Controller
//app.container.registerSingleton<MyController>(MyController());
//await app.mountController<MyController>();
await app.configure(MyController().configureServer);
// Sales Controller
//app.container.registerSingleton<SalesController>(SalesController());
//await app.mountController<SalesController>();
var http = AngelHttp(app);
2023-04-21 06:25:54 +00:00
2023-03-11 04:44:22 +00:00
var server = await http.startServer('localhost', 3000);
print("Angel server listening at ${http.uri}");
}