angular icon indicating copy to clipboard operation
angular copied to clipboard

Repurpose `Inject`

Open chalin opened this issue 7 years ago • 3 comments
trafficstars

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

chalin avatar Apr 13 '18 10:04 chalin

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.

matanlurey avatar Apr 13 '18 17:04 matanlurey

BTW, I'm not sure about nullIfMissing, since I prefer https://github.com/dart-lang/angular/issues/553.

matanlurey avatar Apr 13 '18 17:04 matanlurey

FYI: This was accepted, but will not be done for 5.x. Targeting >=5.1, remove old APIs in 6.0.

matanlurey avatar Apr 13 '18 18:04 matanlurey