feat: change mirrors/reflectable with a `newInstance` getter
Closed this issue · 0 comments
tomassasovsky commented
So I had the idea to replace the use of the reflectable
package fully.
The concept here would be adding a getter to the RouteHandler
class that can be called to create a new instance of the class itself.
Would look like this:
abstract class RouteHandler<T extends RouteHandler<T>> {
FutureOr<dynamic> defineVars(HttpRequest req, HttpResponse res) async {}
// this is the method that is called when the route is called
FutureOr<dynamic> call(HttpRequest req, HttpResponse res) async {
final instance = newInstance;
// this handles the request
await instance.defineVars(req, res);
req.validate();
await instance.run(req, res);
}
FutureOr<dynamic> run(HttpRequest req, HttpResponse res);
// to create a new instance internally
T get newInstance;
}
and an implementation of this:
class SomeMiddleware extends Middleware<SomeMiddleware> {
@override
FutureOr run(HttpRequest req, HttpResponse res) {}
@override
SomeMiddleware get newInstance => SomeMiddleware();
}