spring_core_dart

The core package of Spring for Dart. You declare classes as beans with annotations, and a container creates them, wires them together and configures them. The wiring code is written by spring_core_dart_generator at build time, so nothing is looked up by reflection at run time.

dependencies:
  spring_core_dart: ^0.7.1

dev_dependencies:
  build_runner: ^2.17.0
  spring_core_dart_generator: ^0.7.1
import 'package:spring_core_dart/spring_core_dart.dart';

import 'main.spring.dart';

@Service()
class Greeter {
  Greeter(@Value(r'${greeting:Hello}') this.greeting);

  final String greeting;
}

@ComponentScan()
final BeanModule appBeans = $appBeans;

const log = SpringLog('app');

void main() {
  final context = ApplicationContext.run([appBeans]);
  log.info(context.getBean<Greeter>().greeting);
  context.close();
}

Run dart run build_runner build once, and again after you change the annotations, to write main.spring.dart.

What is inside

Libraries

package:spring_core_dart/spring_core_dart.dart exports everything. A library that needs only one part can import it alone: core.dart, beans.dart, context.dart, expression.dart, json.dart, validation.dart, aop.dart. The Jakarta names (@Inject, @Named) are in jakarta.dart.