2021-09-26 06:53:42 +00:00
|
|
|
# Angel3 Container
|
|
|
|
|
|
|
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_container?include_prereleases)
|
2021-05-14 07:41:25 +00:00
|
|
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
2021-05-15 06:01:47 +00:00
|
|
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
2021-09-26 06:53:42 +00:00
|
|
|
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container/LICENSE)
|
2021-05-14 07:41:25 +00:00
|
|
|
|
2023-04-15 01:09:23 +00:00
|
|
|
A better IoC container for Angel3, ultimately allowing Angel3 to be used with or without `dart:mirrors` package.
|
2021-05-14 07:41:25 +00:00
|
|
|
|
|
|
|
```dart
|
2023-04-15 01:07:24 +00:00
|
|
|
import 'package:angel3_container/mirrors.dart';
|
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
|
|
|
|
@Expose('/sales', middleware: [process1])
|
|
|
|
class SalesController extends Controller {
|
|
|
|
@Expose('/', middleware: [process2])
|
|
|
|
Future<String> route1(RequestContext req, ResponseContext res) async {
|
|
|
|
return "Sales route";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool process1(RequestContext req, ResponseContext res) {
|
2023-04-15 01:09:23 +00:00
|
|
|
res.write('Hello, ');
|
|
|
|
return true;
|
2023-04-15 01:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool process2(RequestContext req, ResponseContext res) {
|
2023-04-15 01:09:23 +00:00
|
|
|
res.write('From Sales, ');
|
|
|
|
return true;
|
2023-04-15 01:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
// Using Mirror Reflector
|
|
|
|
var app = Angel(reflector: MirrorsReflector());
|
|
|
|
|
|
|
|
// Sales Controller
|
|
|
|
app.container.registerSingleton<SalesController>(SalesController());
|
|
|
|
await app.mountController<SalesController>();
|
|
|
|
|
|
|
|
var http = AngelHttp(app);
|
|
|
|
var server = await http.startServer('localhost', 3000);
|
2023-05-21 01:05:14 +00:00
|
|
|
print("Angel3 server listening at ${http.uri}");
|
2023-04-15 01:07:24 +00:00
|
|
|
}
|
2021-09-26 06:53:42 +00:00
|
|
|
```
|