Exemplo n.º 1
0
 private static async Task Response <T>(HttpContext httpContext, AppStatus status, T data)
 {
     var result = new AppResult <T> {
         Status = status, Data = data
     };
     string serialized = JsonSerializer.Serialize(result);
     await AspnetUtils.ResponseOk(httpContext, serialized);
 }
Exemplo n.º 2
0
        public static async Task <T> GetValidatedPayload <T>(HttpContext httpContext, string routeName, Func <Validator[]> onFirstValidation)
        {
            JsonSerializerOptions options;

            if (!RoutesSerializeOptions.ContainsKey(routeName))
            {
                Validator[] validators = onFirstValidation();

                options = new JsonSerializerOptions();
                options.Converters.Add(new ValidationConverter <T>(validators));

                if (!RoutesSerializeOptions.TryAdd(routeName, options))
                {
                    options = RoutesSerializeOptions[routeName];
                }
            }
            else
            {
                options = RoutesSerializeOptions[routeName];
            }

            return(await AspnetUtils.GetPayload <T>(httpContext, options));
        }