Example #1
0
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
            [Inject] ISingletonGreeter singletonGreeter1,
            ILogger logger)
        {
            logger.LogInformation("C# HTTP trigger function processed a request.");

            var result = String.Join(Environment.NewLine, new[] {
                $"Singleton: {singletonGreeter1.Greet()}"
            });

            return(new OkObjectResult(result));
        }
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
            [Inject] ITransientGreeter transientGreeter1,
            [Inject] ITransientGreeter transientGreeter2,
            [Inject] IScopedGreeter scopedGreeter1,
            [Inject] IScopedGreeter scopedGreeter2,
            [Inject] ISingletonGreeter singletonGreeter1,
            [Inject] ISingletonGreeter singletonGreeter2,
            ILogger logger)
        {
            string correlationId = Guid.NewGuid().ToString();

            logger.LogInformation("Odd or even trigger fired - HTTP");
            // {EventDescription}, {EntityType}, {EntityId}, {Status}, {CorrelationId}, {CheckPoint}, {Description}
            logger.LogInformation(new EventId((int)LoggingConstants.EventId.SubmissionSucceeded),
                                  LoggingConstants.Template,
                                  LoggingConstants.EventId.SubmissionSucceeded.ToString(),
                                  LoggingConstants.EntityType.Order.ToString(),
                                  "todo",
                                  LoggingConstants.Status.Succeeded.ToString(),
                                  correlationId,
                                  LoggingConstants.CheckPoint.Publisher.ToString(),
                                  "");

            string numberQueryValue = req.Query["number"];

            if (BigInteger.TryParse(numberQueryValue, out BigInteger number))
            {
                var result = string.Join(Environment.NewLine, new[] {
                    $"Transient: {transientGreeter1.Greet()}",
                    $"Transient: {transientGreeter2.Greet()}",
                    $"Scoped: {scopedGreeter1.Greet()}",
                    $"Scoped: {scopedGreeter2.Greet()}",
                    $"Singleton: {singletonGreeter1.Greet()}",
                    $"Singleton: {singletonGreeter2.Greet()}"
                });
                logger.LogWarning(result);

                string num = number % 2 == 0 ? "Even" : "Odd";

                return(new OkObjectResult(num));
            }

            string message = $"Unable to parse the query parameter 'number'. Got value: {numberQueryValue}";

            logger.LogError(message);

            return(new BadRequestObjectResult(message));
        }