auto_factory 0.1.1

Dart native

Automatically generate code for creating object and their dependecies throug factory classes

Compile ime factories, implmented using source_gen package, so that it works in every platform. The advantages of this approach are are performance (no reflection needed) and full debuggability, as the generated sources are easy to read and well formatted. The development principle is to keep it simple, so only the basics features are implemented.

Install #

To use this package, add auto_factory and build_runner as a dependency in your pubspec.yaml file.

Then, run pub run build_runner build to generate the part files.

Table of contents #

Create a factory #

To make a class part of the dependecy tree annotate the class with the @Component() annotation. The library satisfies the dependency by creating a new instance and injecting to the default constructor the required dependencies.

Note that the injection will work only on default constructor with positional arguments. See example directory.

import 'package:auto_factory/annotations.dart';

part 'myfile.g.dart';

@AutoFactory()
class Component {
  final OtherDependency dep;

  Component(OtherDependency this.dep);
}

/// in another file:
final component = ComponentFactory().get();

component.doSomething();

Caching factories #

Using the @CachingFactory() annotation has the same effect as @AutoFactory() except that the instance is only created the first time. Then the same instance is returned every time

0
likes
90
pub points
1%
popularity

Publisher

msiviero.dev

Automatically generate code for creating object and their dependecies throug factory classes

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

analyzer, auto_factory_annotation, build, meta, path, source_gen

More

Packages that depend on auto_factory