- Update dependencies. Support dart 1.14 sdk.
- Move to analyzer 0.27.1
- Move to guinness2
- Properly transform an
async
main method in an entry point.
- Widen dependency on package:analyzer.
- Widen dependency on package:analyzer.
- Upgraded pubspec dependencies to use newer versions.
- Eliminate dead code and analyzer warnings.
- A class would only be marked as injectable if the first annotation was one of the injectable annotations (GH-191). The DI now checks all the annotations and no more the first one only.
- Fix a bug in FF caused by using a stack trace in a warning message.
This release makes DI 3.0 backward compatible with DI 2.0.
- Annotation assertions are now disabled by default. To enable them set
Module.assertAnnotations
totrue
. - The
di.dart
library now exports Injectable and Injectables. - Core types can be listed in a library level
@Injectables
annotation.
- It is now possible to disable annotation assertion by setting
Module.assertAnnotations
tofalse
(the feature is still enabled by default)
- Revert "perf(Binding): saves a call to
reflector.parameterKeysFor()
" which is buggy
-
Classes could be annotated with a child of
Injectable
to mark them as injectable. Before onlyInjectable
was allowed. -
An annotation instance must be passed when binding with an annotation. Before:
module.bind(MyType, withAnnotation: MyAnnotation);
After:module.bind(MyType, withAnnotation: const MyAnnotation());
The former syntax is deprecated and the support will be dropped in the next major release.
- When assert mode is enabled, the dynamic version of the DI will make sure that the classes are
set up for injection when they are bound. By default classes should either be annotated with
@Injectable
or listed in a library level@Injectables
annotation. The class level and library levels annotations could be changed inModule.classAnnotations
andModule.libAnnotations
.
- It is now possible to inject parameterized types by using
TypeLiteral
:
import 'package:di/type_literal.dart';
class DependencyWithParameterizedMap {
Map<int, String> map;
DependencyWithParameterizedMap(this.map);
}
var injector = new ModuleInjector([moduleFactory()
..bind(new TypeLiteral<Map<int, String>>().type, toValue: {1 : 'first', 2: 'second'})
..bind(DependencyWithParameterizedMap)
]);
- annotations: Users must now explicitly import
di/annotations.dart
to use@Injectable
- Supports newer versions of barback, code transformers, and analyzer
- Binding: Display call stack when usign deprecated bind() form (f20b3ba7)
- There are no longer
StaticInjectors
andDynamicInjectors
. They have been replaced by a newModuleInjector
class that acts as both types of injectors.
- All bindings and instances of parent injectors are now visible in child injectors.
- The optional argument
forceNewInstances
ofInjector.createChild
has been removed Instead, create a new module with bindings of the types that require new instances and pass that to the child injector, and the child injector will create new instances instead of returning the instance of the parent injector.
- The latter is still available but deprecated.
- Injectors with no parent now have a dummy RootInjector instance as the parent Instead of checking “parent == null”, check for “parent == rootInjector”.
-
Old type factories had the form
(injector) => new Instance(injector.get(dep1), … )
-
New factories have the form:
toFactory(a0, a1, …) => new Instance(a0, a1, …)
-
When calling
Module.bind(toFactory: factory)
, there is an additional argumentinject
of a list of types or keys (preferred for performance) whose instances should be passed to the factory. The arguments passed to the factory function will be instances of the types ininject
.Example:
- Old code
module.bind(Car, toFactory: (i) => new Car(i.get(Engine)));
- New code
module.bind(Car, toFactory: (engine) => new Car(engine), inject: [Engine]);
There is also some syntactic sugar for this special case.
- Old code
module.bind(V8Engine, toFactory: (i) => i.get(Engine));
- New code
module.bind(V8Engine, toFactory: (e) => e, inject: [Engine]);
- With sugar
module.bind(V8Engine, toInstanceOf: Engine);
- Old code
- The
TypeReflector
is how the module will find thetoFactory
andinject
arguments when not explicitly specified. This is either done with mirroring or code generation via transformers. Transformers will set the default to use code gen. For testing and other special purposes where a specific reflector is needed, usenew Module.withReflector(reflector)
.
- Running the transformer will do the necessary code generation and edits to switch the
default
TypeReflector
from mirroring to static factories. Enable transformer to use static factories, disable to use mirrors. More docs on the transformer can be found intransformer.dart
.value
,.type
,.factory
,.factoryByKey
are gone. Use..bind
.
module.bind()
calls specifying theinject
parameter but notoFactory
have been deprecated and will be removed in v3. Use thetoInstanceOf
parameter instead.- The dynamic injector shim (dynamic_injector.dart) has been added to ensure backward compatibility with v1 and will be removed in v3.
- module: Expose DEFAULT_VALUE temporarily (6f5d88a1)
Reverted changes that tickled a Dart bug (to be fixed in 1.6)
Added missing library declaration to injector.
- module: allow v2 style toFactory binding with inject (1ef6ba71)
- injector: inlined getProviderWithInjector (d2a38b54)
- injector: optimized module to injector instantiation (62f22f15)
Starting with this release DI is following semver.
- Key: fixed bugs caused by hashCode collisions, and docs cleanup (f673267d, #94)
- circular deps: Improve error messages (4ccdb1f0)
- Key: don't use Map.putIfAbsent -- too slow (0930b377)
- injector: use separate structures to allow compiler optimizations (f7b8af92)
- transformer: Exception on parameterized types with implicit constructors (ed0a2b02)
Module has a new API:
new Module()
..bind(Foo, toValue: new Foo())
..bind(Foo, toFactory: (i) => new Foo())
..bind(Foo, toImplementation: FooImpl);
Old methods type
, value
and factory
were deprecated and will be removed in the next release.
- key: made Key part of di.dart again (fe390ddf)
Combined with previous release (0.0.36) injector is on average 2x faster.
Before:
VM:
DynamicInjectorBenchmark(RunTime): 231.93784065870346 us.
StaticInjectorBenchmark(RunTime): 107.05491917353602 us.
dart2js:
DynamicInjectorBenchmark(RunTime): 2175 us.
StaticInjectorBenchmark(RunTime): 765.1109410864575 us.
After:
VM:
DynamicInjectorBenchmark(RunTime): 156.3721657544957 us.
StaticInjectorBenchmark(RunTime): 54.246114622040196 us.
dart2js:
DynamicInjectorBenchmark(RunTime): 1454.5454545454545 us.
StaticInjectorBenchmark(RunTime): 291.9281856663261 us.
- warnings: refactored injector to fix analyzer warnings (7d374b19)
- injector:
- resolvedTypes: minor performance inmprovement in resolvedTypes (ba16bde5)
- injector:
- skip _checkKeyConditions in dart2js (6763552a)
- +29%. Use an array for type lookup instead of a map.