diana 0.15.1
diana: ^0.15.1 copied to clipboard
Spring-inspired, annotation-driven backend framework for Dart: compile- time dependency injection, declarative controllers, middleware and validation.
diana example #
A minimal Diana API: one injected service and one controller. Add the runtime, and the generator as a dev dependency:
dependencies:
diana: ^0.15.1
dev_dependencies:
build_runner: ^2.12.0
diana_generator: ^0.15.1
// 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/.