SI-7918 Use scala.util.DynamicVariable instead of ad hoc implementations