public static T Bind <T>(this T query, Id instanceId) where T : Query { var queryType = query.GetType(); var areaMap = AreaMap.From(new[] { queryType }); AreaTypeName.TryFrom(queryType.Name, out var areaType); var flowType = areaMap.GetFlow(areaType); var subscriptionKey = FlowKey.From(flowType, instanceId); FlowContext.Bind(query, subscriptionKey); return(query); }
public static bool TryFrom(string value, AreaMap area, out FlowKey key) { var idIndex = value.IndexOf(Id.Separator); var typePart = idIndex == -1 ? value : value.Substring(0, idIndex); var idPart = idIndex == -1 ? "" : value.Substring(idIndex + 1); key = AreaTypeName.TryFrom(typePart, out var typeKey) && area.TryGetFlow(typeKey, out var type) ? new FlowKey(type, Id.From(idPart)) : null; return(key != null); }