Skip to content
This repository was archived by the owner on Dec 6, 2017. It is now read-only.

DI 2.0.0 #135

Merged
merged 5 commits into from
Jul 23, 2014
Merged

DI 2.0.0 #135

merged 5 commits into from
Jul 23, 2014

Conversation

jbdeboer
Copy link
Contributor

No description provided.


## Example

```dart
import 'package:di/di.dart';
import 'package:di/auto_injector.dart';
import 'package:di/di_dynamic.dart';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out-of-date, please update.

factoriesBuffer.write(' $typeName: ($args) => new $typeName($args),\n');

paramsBuffer.write(' $typeName: ');
paramsBuffer.write(ctor.parameters.length == 0 ? 'const[' : '[');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmpty

@vicb
Copy link
Contributor

vicb commented Jul 15, 2014

I've done a first round of comments going through the new code.
I'll look more closely at the code logic tomorrow morning (my time).

BTW: transformer tests are failing (see travis)

barback: '>=0.13.0 <0.14.0'
code_transformers: '>=0.1.3 <0.2.0'
analyzer: '>=0.15.0 <0.19.0'
barback: '>=0.13.0 <0.17.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be '>=0.13.0 <0.15.0', the current version is 0.14.1+3 and 0.15+ might have backward compatibility breaks

@antingshen
Copy link
Contributor

Fixes for comments up to now are in #132

@@ -268,16 +282,20 @@ createInjectorSpec(String injectorName, InjectorFactory injectorFactory) {
});

it('should fail if no binding is found', () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replacing this test, add a new one: 'should fail if no binding is found resolving dependencies'

@vicb
Copy link
Contributor

vicb commented Jul 16, 2014

Thanks for fixing the issues and giving some explanations, great job!

cbracken and others added 5 commits July 23, 2014 11:15
BREAKING CHANGE
- Calls to StaticInjector and DynamicInjector should be replaced with ModuleInjector
  - There are no longer StaticInjectors and DynamicInjectors. They have been replaced
    by a new ModuleInjector class that acts as both types of injectors. There is also
    a faster NodeInjector class for specific use cases where many injector features
    aren’t needed. (Miško has more info on NodeInjectors)

- ModuleInjectors have no visibility
  - All bindings and instances of parent injectors are now visible in child injectors.
    NodeInjectors do, however, have some sense of visibility.
  - The optional argument “forceNewInstances” of Injector.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.

- Use “new ModuleInjector(modules, parent)” instead of “Injector.createChild(modules)”
  - 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”.

- Injectors no longer have a name field

- typeFactories have changed
  - Old type factories had the form (injector) => new Instance(injector.get(dep1), … )
  - New factories have one of:
    - toFactory(a0, a1) => new Instance(a0, a1)
  - When calling Module.bind(toFactory: factory), there is an additional argument “inject”
    of a list of types or keys (preferred for performance) whose instances should be
    passed to the factory. The array “p” passed to the factory function will be instances
    of the types in “inject”.

    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(Engine, toFactory: (i) => i.get(Engine));
    - New code. module.bind(Engine, toFactory: (e) => e, inject: [Engine]);
    - With sugar. module.bind(Engine, toInstanceOf: Engine);

- Modules have a TypeReflector instance attached
  - The TypeReflector is how the module will find the “toFactory” and “inject”
    arguments when not explicitly specified. This is either done with mirroring or code
    generation via transformers. Typical use will not need to worry about this at all, and
    the default reflector will suffice. If needed, implement TypeReflector and use
    new Module.withReflector(reflector).

- The transformer has been updated
  - 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 in
    transformer.dart

- And it’s lots faster!
@jbdeboer
Copy link
Contributor Author

LGTM. Feel free to push.

@mhevery mhevery merged commit 279be49 into master Jul 23, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants