Closed patskovn closed 6 years ago
it's https://github.com/ivlevAstef/DITranquillity/issues/124.
Эта реализация может узнать тэг только в момент исполнения кода. То есть не получится проверить граф на корректность.
Разве сейчас по имени нет возможности проверить граф на корректность?
Есть. но у имени кастрированный функционал - его например нельзя задать в методе инициализации. Кокраз таки из-за того что надо было сохранять валидацию.
Proposal. Problem: Current implementation of “tags” in library based on objects types (or strings, but its not compile-safe). It is not possible now to use polymorphism like:
Resolver will produce
nil
inmyOBJ
resolving, cause container will be used compile-time type of tag (A.Type), not actual type stored in tag variable.And now we hame “name” feature that can be used similar way as tags, but string not compile-safe and it is easy to make typo mistake during development. Because both “name” and “tag” exists in library, one of them looks like a hack, that exists for solving problem of opposite implementation.
Proposal: For easier and more intuitive usage of marking registrations I suggest implement Notification.Name-like implementation or Enum implementation.
Variant1:
Variant2:
Pros:
Difference between two variants: In variant 1 anyone from another frameworks can get access to your tagged variable without actually having access to internal tag if you declare DITag.Scope as public just by passing same string value in DITag initialisation. In variant 2, you have no possibility to share access to tag, because of capturing enum’s type in “as(_:tag:)” registration. Enum’s type capturing is mandatory cause of enum’s case string values overlapping.