diana_annotation 0.15.1
diana_annotation: ^0.15.1 copied to clipboard
Annotations for the Diana backend framework. Pure constants, no runtime dependencies.
diana_annotation example #
diana_annotation holds the constant annotations (@RestController,
@Service, @Get, @Value, …). Applications don't depend on it
directly — package:diana re-exports it — so it is used like this:
// lib/app.dart — anchors the generated composition root
import 'package:diana/diana.dart';
@DianaApplication()
class MyApp {}
// lib/greeting_service.dart
import 'package:diana/diana.dart';
@Service()
class GreetingService {
final String prefix;
GreetingService(@Value('app.greeting', defaultValue: 'Hello') this.prefix);
String greet(String name) => '$prefix, $name!';
}
// lib/hello_controller.dart
import 'package:diana/diana.dart';
import 'greeting_service.dart';
part 'hello_controller.diana.dart';
@RestController('/hello')
class HelloController {
final GreetingService greetings; // injected at compile time
HelloController(this.greetings);
@Get()
Map<String, dynamic> hello() => {'message': 'Hello from Diana!'};
@Get('/:name')
String greet(@PathParam() String name) => greetings.greet(name);
}
// bin/server.dart
import 'package:my_api/app.diana_app.dart';
Future<void> main() => runDiana();
dart run build_runner build # emits *.diana.dart and app.diana_app.dart
dart run bin/server.dart # [diana] Listening on http://0.0.0.0:8080
curl localhost:8080/hello/dart # Hello, dart!
More complete, runnable apps live in the repository's examples, and the full documentation is at https://carmonac.github.io/diana-be-framework/.