diff --git a/CHANGELOG.md b/CHANGELOG.md index 287c5f52..b4402878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,4 +9,5 @@ * Remove dependency on `package:dart2_constant`. * Remove `contentType` argument in `ResponseContext.serialize`. * Moved `lib/hooks.dart` into `package:angel_hooks`. -* Moved `TypedService` into `package:angel_typed_service`. \ No newline at end of file +* Moved `TypedService` into `package:angel_typed_service`. +* Completely removed the `AngelBase` class. \ No newline at end of file diff --git a/lib/src/core/angel_base.dart b/lib/src/core/angel_base.dart deleted file mode 100644 index a1d0cc37..00000000 --- a/lib/src/core/angel_base.dart +++ /dev/null @@ -1,50 +0,0 @@ -library angel_framework.http.angel_base; - -import 'dart:async'; - -import 'package:angel_container/angel_container.dart'; - -import 'routable.dart'; - -/// A function that asynchronously generates a view from the given path and data. -typedef FutureOr ViewGenerator(String path, - [Map data]); - -/// Base class for Angel servers. Do not bother extending this. -class AngelBase extends Routable { - static ViewGenerator noViewEngineConfigured = - (String view, [Map data]) => 'No view engine has been configured yet.'; - - Container _container; - - AngelBase(Reflector reflector) { - _container = new Container(reflector); - } - - final Map configuration = {}; - - /// When set to true, the request body will not be parsed - /// automatically. You can call `req.parse()` manually, - /// or use `lazyBody()`. - bool lazyParseBodies = false; - - /// When set to `true`, the original body bytes will be stored - /// on requests. `false` by default. - bool storeOriginalBuffer = false; - - /// A [Container] used to inject dependencies. - Container get container => _container; - - /// A function that renders views. - /// - /// Called by [ResponseContext]@`render`. - ViewGenerator viewGenerator = noViewEngineConfigured; - - /// Closes this instance, rendering it **COMPLETELY DEFUNCT**. - Future close() { - super.close(); - _container = null; - viewGenerator = noViewEngineConfigured; - return new Future.value(); - } -} diff --git a/lib/src/core/routable.dart b/lib/src/core/routable.dart index f39ae109..ec9c1fcf 100644 --- a/lib/src/core/routable.dart +++ b/lib/src/core/routable.dart @@ -129,7 +129,7 @@ class Routable extends Router { final handlers = []; - if (_router is AngelBase) { + if (_router is Angel) { handlers.add((RequestContext req, ResponseContext res) { req.app = _router as Angel; res.app = _router as Angel; diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index 40fd18ac..5caa5413 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -15,7 +15,6 @@ import 'package:meta/meta.dart'; import 'package:tuple/tuple.dart'; import '../http/http.dart'; -import 'angel_base.dart'; import 'request_context.dart'; import 'response_context.dart'; import 'routable.dart'; @@ -32,8 +31,15 @@ typedef Future ServerGenerator(address, int port); /// A function that configures an [Angel] server in some way. typedef FutureOr AngelConfigurer(Angel app); +/// A function that asynchronously generates a view from the given path and data. +typedef FutureOr ViewGenerator(String path, + [Map data]); + /// A powerful real-time/REST/MVC server class. -class Angel extends AngelBase { +class Angel extends Routable { + static ViewGenerator noViewEngineConfigured = + (String view, [Map data]) => 'No view engine has been configured yet.'; + final List _children = []; final Map>>> handlerCache = new HashMap(); @@ -118,6 +124,33 @@ class Angel extends AngelBase { /// All global dependencies injected into the application. Map get injections => _injections; + Container _container; + + /// A [Map] of application-specific data that can be accessed by any + /// piece of code that can see this [Angel] instance. + /// + /// Packages like `package:angel_configuration` populate this map + /// for you. + final Map configuration = {}; + + /// When set to true, the request body will not be parsed + /// automatically. You can call `req.parse()` manually, + /// or use `lazyBody()`. + bool lazyParseBodies = false; + + /// When set to `true`, the original body bytes will be stored + /// on requests. `false` by default. + bool storeOriginalBuffer = false; + + /// A [Container] used to inject dependencies. + Container get container => _container; + + /// A function that renders views. + /// + /// Called by [ResponseContext]@`render`. + ViewGenerator viewGenerator = noViewEngineConfigured; + + /// // /// Use [configuration] instead. @deprecated Map get properties { @@ -196,7 +229,7 @@ class Angel extends AngelBase { /// Loads some base dependencies into the service container. void bootstrapContainer() { if (runtimeType != Angel) container.singleton(this, as: Angel); - container.singleton(this, as: AngelBase); + container.singleton(this, as: Angel); container.singleton(this, as: Routable); container.singleton(this, as: Router); container.singleton(this); @@ -204,13 +237,15 @@ class Angel extends AngelBase { /// Shuts down the server, and closes any open [StreamController]s. /// - /// The server will be **COMPLETE DEFUNCT** after this operation! + /// The server will be **COMPLETELY DEFUNCT** after this operation! Future close() { Future.forEach(services.values, (Service service) { service.close(); }); super.close(); + _container = null; + viewGenerator = noViewEngineConfigured; _preContained.clear(); handlerCache.clear(); _injections.clear(); @@ -484,8 +519,8 @@ class Angel extends AngelBase { return super.use(path, routable, namespace); } - /// Default constructor. ;) - Angel({@required Reflector reflector}) : super(reflector) { + Angel({@required Reflector reflector}) { + _container = new Container(reflector); bootstrapContainer(); // ignore: deprecated_member_use createZoneForRequest = defaultZoneCreator; diff --git a/lib/src/core/service.dart b/lib/src/core/service.dart index 659ee639..521e5bb7 100644 --- a/lib/src/core/service.dart +++ b/lib/src/core/service.dart @@ -4,12 +4,12 @@ import 'dart:async'; import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:merge_map/merge_map.dart'; import '../util.dart'; -import 'angel_base.dart'; import 'hooked_service.dart' show HookedService; import 'metadata.dart'; import 'request_context.dart'; import 'response_context.dart'; import 'routable.dart'; +import 'server.dart'; /// Indicates how the service was accessed. /// @@ -59,7 +59,7 @@ class Service extends Routable { List get bootstrappers => []; /// The [Angel] app powering this service. - AngelBase app; + Angel app; /// Closes this service, including any database connections or stream controllers. void close() {}