Пример #1
0
        public static async Task <IActionResult> ExecuteAction <TF>(IAutoFeatureContainer kernelContainer, Func <TF, Task <IActionResult> > featureCall)
        {
            var log = kernelContainer.Kernel.Get <ILogger>();

            try
            {
                var feature = kernelContainer.Kernel.Get <TF>();
                var result  = await featureCall(feature);

                return(result);
            }
            catch (Exception e)
            {
                log.Log(LogLevel.Error, e, e.ToString());
                return(new InternalServerErrorResult());
            }
        }
Пример #2
0
        public static async Task <IActionResult> ExecuteVoidWithBody <TF, TB>(IAutoFeatureContainer kernelContainer, HttpRequest request, Func <TF, TB, Task> featureCall)
        {
            var log = kernelContainer.Kernel.Get <ILogger>();

            try
            {
                var feature        = kernelContainer.Kernel.Get <TF>();
                var bodySerialized = await request.ReadAsStringAsync();

                var bodyDeserialized = JsonConvert.DeserializeObject <TB>(bodySerialized);
                await featureCall(feature, bodyDeserialized);

                return(new OkResult());
            }
            catch (Exception e)
            {
                log.Log(LogLevel.Error, e, e.ToString());
                return(new InternalServerErrorResult());
            }
        }