Completely removed the AngelBase
class
This commit is contained in:
parent
1fcb57d53b
commit
79818cf001
5 changed files with 46 additions and 60 deletions
|
@ -9,4 +9,5 @@
|
||||||
* Remove dependency on `package:dart2_constant`.
|
* Remove dependency on `package:dart2_constant`.
|
||||||
* Remove `contentType` argument in `ResponseContext.serialize`.
|
* Remove `contentType` argument in `ResponseContext.serialize`.
|
||||||
* Moved `lib/hooks.dart` into `package:angel_hooks`.
|
* Moved `lib/hooks.dart` into `package:angel_hooks`.
|
||||||
* Moved `TypedService` into `package:angel_typed_service`.
|
* Moved `TypedService` into `package:angel_typed_service`.
|
||||||
|
* Completely removed the `AngelBase` class.
|
|
@ -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<String> ViewGenerator(String path,
|
|
||||||
[Map<String, dynamic> 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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -129,7 +129,7 @@ class Routable extends Router {
|
||||||
|
|
||||||
final handlers = [];
|
final handlers = [];
|
||||||
|
|
||||||
if (_router is AngelBase) {
|
if (_router is Angel) {
|
||||||
handlers.add((RequestContext req, ResponseContext res) {
|
handlers.add((RequestContext req, ResponseContext res) {
|
||||||
req.app = _router as Angel;
|
req.app = _router as Angel;
|
||||||
res.app = _router as Angel;
|
res.app = _router as Angel;
|
||||||
|
|
|
@ -15,7 +15,6 @@ import 'package:meta/meta.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
import '../http/http.dart';
|
import '../http/http.dart';
|
||||||
import 'angel_base.dart';
|
|
||||||
import 'request_context.dart';
|
import 'request_context.dart';
|
||||||
import 'response_context.dart';
|
import 'response_context.dart';
|
||||||
import 'routable.dart';
|
import 'routable.dart';
|
||||||
|
@ -32,8 +31,15 @@ typedef Future<HttpServer> ServerGenerator(address, int port);
|
||||||
/// A function that configures an [Angel] server in some way.
|
/// A function that configures an [Angel] server in some way.
|
||||||
typedef FutureOr AngelConfigurer(Angel app);
|
typedef FutureOr AngelConfigurer(Angel app);
|
||||||
|
|
||||||
|
/// A function that asynchronously generates a view from the given path and data.
|
||||||
|
typedef FutureOr<String> ViewGenerator(String path,
|
||||||
|
[Map<String, dynamic> data]);
|
||||||
|
|
||||||
/// A powerful real-time/REST/MVC server class.
|
/// 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<Angel> _children = [];
|
final List<Angel> _children = [];
|
||||||
final Map<String, Tuple3<List, Map, ParseResult<Map<String, dynamic>>>>
|
final Map<String, Tuple3<List, Map, ParseResult<Map<String, dynamic>>>>
|
||||||
handlerCache = new HashMap();
|
handlerCache = new HashMap();
|
||||||
|
@ -118,6 +124,33 @@ class Angel extends AngelBase {
|
||||||
/// All global dependencies injected into the application.
|
/// All global dependencies injected into the application.
|
||||||
Map get injections => _injections;
|
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.
|
/// Use [configuration] instead.
|
||||||
@deprecated
|
@deprecated
|
||||||
Map get properties {
|
Map get properties {
|
||||||
|
@ -196,7 +229,7 @@ class Angel extends AngelBase {
|
||||||
/// Loads some base dependencies into the service container.
|
/// Loads some base dependencies into the service container.
|
||||||
void bootstrapContainer() {
|
void bootstrapContainer() {
|
||||||
if (runtimeType != Angel) container.singleton(this, as: Angel);
|
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: Routable);
|
||||||
container.singleton(this, as: Router);
|
container.singleton(this, as: Router);
|
||||||
container.singleton(this);
|
container.singleton(this);
|
||||||
|
@ -204,13 +237,15 @@ class Angel extends AngelBase {
|
||||||
|
|
||||||
/// Shuts down the server, and closes any open [StreamController]s.
|
/// 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 close() {
|
||||||
Future.forEach(services.values, (Service service) {
|
Future.forEach(services.values, (Service service) {
|
||||||
service.close();
|
service.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
super.close();
|
super.close();
|
||||||
|
_container = null;
|
||||||
|
viewGenerator = noViewEngineConfigured;
|
||||||
_preContained.clear();
|
_preContained.clear();
|
||||||
handlerCache.clear();
|
handlerCache.clear();
|
||||||
_injections.clear();
|
_injections.clear();
|
||||||
|
@ -484,8 +519,8 @@ class Angel extends AngelBase {
|
||||||
return super.use(path, routable, namespace);
|
return super.use(path, routable, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default constructor. ;)
|
Angel({@required Reflector reflector}) {
|
||||||
Angel({@required Reflector reflector}) : super(reflector) {
|
_container = new Container(reflector);
|
||||||
bootstrapContainer();
|
bootstrapContainer();
|
||||||
// ignore: deprecated_member_use
|
// ignore: deprecated_member_use
|
||||||
createZoneForRequest = defaultZoneCreator;
|
createZoneForRequest = defaultZoneCreator;
|
||||||
|
|
|
@ -4,12 +4,12 @@ import 'dart:async';
|
||||||
import 'package:angel_http_exception/angel_http_exception.dart';
|
import 'package:angel_http_exception/angel_http_exception.dart';
|
||||||
import 'package:merge_map/merge_map.dart';
|
import 'package:merge_map/merge_map.dart';
|
||||||
import '../util.dart';
|
import '../util.dart';
|
||||||
import 'angel_base.dart';
|
|
||||||
import 'hooked_service.dart' show HookedService;
|
import 'hooked_service.dart' show HookedService;
|
||||||
import 'metadata.dart';
|
import 'metadata.dart';
|
||||||
import 'request_context.dart';
|
import 'request_context.dart';
|
||||||
import 'response_context.dart';
|
import 'response_context.dart';
|
||||||
import 'routable.dart';
|
import 'routable.dart';
|
||||||
|
import 'server.dart';
|
||||||
|
|
||||||
/// Indicates how the service was accessed.
|
/// Indicates how the service was accessed.
|
||||||
///
|
///
|
||||||
|
@ -59,7 +59,7 @@ class Service extends Routable {
|
||||||
List get bootstrappers => [];
|
List get bootstrappers => [];
|
||||||
|
|
||||||
/// The [Angel] app powering this service.
|
/// The [Angel] app powering this service.
|
||||||
AngelBase app;
|
Angel app;
|
||||||
|
|
||||||
/// Closes this service, including any database connections or stream controllers.
|
/// Closes this service, including any database connections or stream controllers.
|
||||||
void close() {}
|
void close() {}
|
||||||
|
|
Loading…
Reference in a new issue