angular
angular copied to clipboard
Repurpose `Inject`
Since https://github.com/dart-lang/angular/commit/cfab80fa46e9388f5a7defe46951e8839619b842, we can now use an OpaqueToken directly as an annotation instead of having to wrap it in @Inject(). Here is the example from that commit:
const baseUrl = const OpaqueToken<String>('baseUrl');
class Comp1 {
Comp1(@Inject(baseUrl) String url);
}
class Comp2 {
Comp2(@baseUrl String url);
}
Is there any other use for Inject? If not, how about deprecating it?
Related: #1236
cc @kwalrath
Good question. One thing we discussed was Injection-selection APIs.
Here is my idea, as I hate having 4-5 top-level annotations for this purpose: (from https://github.com/dart-lang/angular/pull/1186)
abstract class Inject {
// Used to be @SkipSelf()
static const fromAncestors = const ...;
// Used to be @Parent()
static const fromParent = const ...;
// Used to be @Self()
static const fromSelf = const ...;
// Used to be @Optional()
static const nullIfMissing = const ...;
const Inject._;
}
... and then keeping around Inject just as a namespace here.
BTW, I'm not sure about nullIfMissing, since I prefer https://github.com/dart-lang/angular/issues/553.
FYI: This was accepted, but will not be done for 5.x. Targeting >=5.1, remove old APIs in 6.0.