dart-backend / angel

A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://github.com/dukefirehawk/angel
BSD 3-Clause "New" or "Revised" License
171 stars 22 forks source link

StaticReflector or GeneratedReflector usage #92

Closed victor7w7r closed 8 months ago

victor7w7r commented 1 year ago

How i can use the StaticReflector for DI, i don't have any examples for usage, in my case i need to register my controller without success

Expose('/controller')
class MyController extends Controller{

  @Expose('/')
  a() => "Hello, world!";
}

void main() async {

  var reflector = const GeneratedReflector();
  Container container = Container(reflector);

  container.registerSingleton<MyController>(MyController());

  //initializeReflectable();

  var app = Angel(reflector: reflector);

  var http = AngelHttp(app);

  await app.mountController<MyController>();

  var server = await http.startServer();
  print("Angel server listening at ${http.uri}");

Please help and thanks.

victor7w7r commented 1 year ago

I have to use @contained for generate, but @Expose not work properly for build, please help 😢

import 'dev.reflectable.dart';

@contained
@Expose('/controller')
class MyController extends Controller {

  @Expose('/')
  a() => "Hello, world!";
}

void main() async {

  initializeReflectable();

  final reflector = GeneratedReflector();

  var app = Angel(reflector: reflector);
  var http = AngelHttp(app);

  await app.mountController<MyController>();

  print("Angel server listening at ${http.uri}");
}
dukefirehawk commented 1 year ago

There are some limitations to using reflectable for reflection. Work in progress to update the documents and examples.

victor7w7r commented 8 months ago

I'm amazed by this project, I wish there was more documentation to build my app in standalone mode, without using the SDK container, thanks and keep maintaining this project