From 168c51074bcbf26640c1e1714b80483a742782da Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sat, 15 Apr 2023 09:07:24 +0800 Subject: [PATCH] Published angel2_container --- .../example2/bin/example3_controller.dart | 2 +- .../container/angel_container/CHANGELOG.md | 8 ++-- packages/container/angel_container/README.md | 37 ++++++++++++++++++- .../angel_container/lib/src/empty/empty.dart | 10 +++++ .../lib/src/mirrors/reflector.dart | 5 +++ .../container/angel_container/pubspec.yaml | 2 +- .../container/angel_container_generator/= | 0 packages/orm/angel_orm_generator/pubspec.yaml | 2 +- 8 files changed, 56 insertions(+), 10 deletions(-) delete mode 100644 packages/container/angel_container_generator/= diff --git a/experiment/container/example2/bin/example3_controller.dart b/experiment/container/example2/bin/example3_controller.dart index bd6fb076..9fdde382 100644 --- a/experiment/container/example2/bin/example3_controller.dart +++ b/experiment/container/example2/bin/example3_controller.dart @@ -47,7 +47,7 @@ void main() async { //Container container = Container(reflector); //container.registerSingleton(SalesController()); - // Useing GeneratedReflector + // Using GeneratedReflector initializeReflectable(); var app = Angel(reflector: GeneratedReflector()); diff --git a/packages/container/angel_container/CHANGELOG.md b/packages/container/angel_container/CHANGELOG.md index fc5e7dc8..e764f75c 100644 --- a/packages/container/angel_container/CHANGELOG.md +++ b/packages/container/angel_container/CHANGELOG.md @@ -1,12 +1,10 @@ # Change Log -## 7.1.1 - -* Moved `defaultErrorMessage` to `ContainerConst` class to resolve reflectatable issue. - -## 7.1.0 +## 7.1.0-beta.1 * Require Dart >= 2.18 +* Moved `defaultErrorMessage` to `ContainerConst` class to resolve reflectatable issue. +* Added `hashCode` ## 7.0.0 diff --git a/packages/container/angel_container/README.md b/packages/container/angel_container/README.md index 770192f6..91f3491e 100644 --- a/packages/container/angel_container/README.md +++ b/packages/container/angel_container/README.md @@ -5,8 +5,41 @@ [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container/LICENSE) -An better IoC container for Angel3, ultimately allowing Angel3 to be used without `dart:mirrors` package. +An better IoC container for Angel3, ultimately allowing Angel3 to be used with or without `dart:mirrors` package. ```dart -import 'package:angel3_container/angel3_container.dart'; + 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 route1(RequestContext req, ResponseContext res) async { + return "Sales route"; + } + } + + bool process1(RequestContext req, ResponseContext res) { + res.write('Hello, '); + return true; + } + + bool process2(RequestContext req, ResponseContext res) { + res.write('From Sales, '); + return true; + } + + void main() async { + // Using Mirror Reflector + var app = Angel(reflector: MirrorsReflector()); + + // Sales Controller + app.container.registerSingleton(SalesController()); + await app.mountController(); + + var http = AngelHttp(app); + var server = await http.startServer('localhost', 3000); + print("Angel server listening at ${http.uri}"); + } ``` diff --git a/packages/container/angel_container/lib/src/empty/empty.dart b/packages/container/angel_container/lib/src/empty/empty.dart index 8869d00d..81176c37 100644 --- a/packages/container/angel_container/lib/src/empty/empty.dart +++ b/packages/container/angel_container/lib/src/empty/empty.dart @@ -1,4 +1,5 @@ import '../../angel3_container.dart'; +import 'package:quiver/core.dart'; final Map _symbolNames = {}; @@ -66,6 +67,9 @@ class _EmptyReflectedClass extends ReflectedClass { bool operator ==(other) { return other is ReflectedClass && other.hashCode == hashCode; } + + @override + int get hashCode => hash2(this, " "); } class _EmptyReflectedType extends ReflectedType { @@ -90,6 +94,9 @@ class _EmptyReflectedType extends ReflectedType { bool operator ==(other) { return other is ReflectedType && other.hashCode == hashCode; } + + @override + int get hashCode => hash2(this, " "); } class _EmptyReflectedInstance extends ReflectedInstance { @@ -101,6 +108,9 @@ class _EmptyReflectedInstance extends ReflectedInstance { return other is ReflectedInstance && other.hashCode == hashCode; } + @override + int get hashCode => hash2(this, " "); + @override ReflectedInstance getField(String name) { throw UnsupportedError( diff --git a/packages/container/angel_container/lib/src/mirrors/reflector.dart b/packages/container/angel_container/lib/src/mirrors/reflector.dart index 800d5d93..e534fae5 100644 --- a/packages/container/angel_container/lib/src/mirrors/reflector.dart +++ b/packages/container/angel_container/lib/src/mirrors/reflector.dart @@ -4,6 +4,8 @@ import 'dart:mirrors' as dart; import '../exception.dart'; import '../reflector.dart'; +import 'package:quiver/core.dart'; + /// A [Reflector] implementation that forwards to `dart:mirrors`. /// /// Useful on the server, where reflection is supported. @@ -176,6 +178,9 @@ class _ReflectedClassMirror extends ReflectedClass { bool operator ==(other) { return other is _ReflectedClassMirror && other.mirror == mirror; } + + @override + int get hashCode => hash2(mirror, " "); } class _ReflectedDeclarationMirror extends ReflectedDeclaration { diff --git a/packages/container/angel_container/pubspec.yaml b/packages/container/angel_container/pubspec.yaml index 1972d57d..45fa4e36 100644 --- a/packages/container/angel_container/pubspec.yaml +++ b/packages/container/angel_container/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_container -version: 7.1.1 +version: 7.1.0-beta.1 description: Angel3 hierarchical DI container, and pluggable backends for reflection. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container diff --git a/packages/container/angel_container_generator/= b/packages/container/angel_container_generator/= deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/orm/angel_orm_generator/pubspec.yaml b/packages/orm/angel_orm_generator/pubspec.yaml index ef417d3a..e130da6f 100644 --- a/packages/orm/angel_orm_generator/pubspec.yaml +++ b/packages/orm/angel_orm_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_orm_generator -version: 7.1.2 +version: 7.1.3 description: Code generators for Angel3 ORM. Generates query builder classes. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_generator