ltackmann / dice

Lightweight dependency injection framework for Dart
Other
34 stars 7 forks source link

Use @inject annotation instead of $/_$ #5

Closed ltackmann closed 11 years ago

ltackmann commented 11 years ago

See example here

https://github.com/ltackmann/dart-samples/blob/master/lang/meta_test.dart

ltackmann commented 11 years ago

I will look into it myself also ;)

ggirou commented 11 years ago

I can't try your example at work, is it working ?

ltackmann commented 11 years ago

just tested successfully with

Dart Editor version 0.5.20_r24216 Dart SDK version 0.5.20.3_r24216

ggirou commented 11 years ago

Great! :) I'm quite busy actually but I'll try to have a look as well. Do we also keep the current behavior with the $ prefix ?

ltackmann commented 11 years ago

I believe its best to dump the current $ behavior. There are not so many users yet, so if we are to dump it now is the time ;)

ggirou commented 11 years ago

Ok

ltackmann commented 11 years ago

@ggirou added a proposal for how the inject annotation can be used

https://github.com/ltackmann/dice/blob/master/test/test_module.dart

I wonder if its best to have a seperate Named annotation like guice for named injections ?. Personally I prefer

@Inject(name:"some name")

over

@Inject @Named("some name")

WDYT ?

ggirou commented 11 years ago

I think it's important to keep them separate, specially for the constructors :

@Inject MyObject.construct(@Named("scope1") firstParameter, @Named("scope2") secondParameter) => ...

ltackmann commented 11 years ago

Right I will fix it ;)

ltackmann commented 11 years ago

Fixed

https://github.com/ltackmann/dice/blob/master/test/test_module.dart https://github.com/ltackmann/dice/blob/master/lib/src/annotations.dart

Also here is a bigger more complex example off how to use the meta data API

https://github.com/ltackmann/dart-samples/blob/aefee64bea51cc81fbb8638e65d069ec65c02dde/lang/meta_test.dart