injectable icon indicating copy to clipboard operation
injectable copied to clipboard

How to implement open generics?

Open JCKodel opened this issue 1 year ago • 2 comments

Let's assume I have an interface ILogger<T> and this implementation:

final class Logger<T> implements ILogger<T> {
  const Logger();

  void print(String message) {
    // From dart:dev:
    log(message, name: T.toString());
  }
}

I want to be able to use that class with open generics (a concept in C# that allows, for instance, registration of a dependency of type ILogger<>: the missing T meaning "any type").

So, in some service, I would do:

final class SomeService {
  const SomeService({required this.logger});

  final ILogger<SomeService> logger;
}

So this particular service would print stuff such as

[SomeService] Some log message

Is there some way to accomplish that?

JCKodel avatar Oct 16 '23 19:10 JCKodel

Hey @JCKodel this needs to be supported by get_it first.

Milad-Akarie avatar Oct 18 '23 10:10 Milad-Akarie

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Nov 18 '23 08:11 github-actions[bot]