How to add Middleware in Azure HttpTrigger Functions (in-process function app) (Microsoft.NET.Sdk.Functions) in .net

KushalSeth

I found one sample on Stackoverflow (How to insert a middleware in Azure Durable Functions), but it also just talks about Isolated and Duarable Trigger functions. I want to add middlelayer in Azure HttpTrigger (Microsoft.NET.Sdk.Functions) Functions in .net

I am creating a project in .Net 6. This project will have HttpTrigger type of Azure functions.

When I created the default project from Visual Studio Azure function template, it has just created a simple function file and project without startup and Program.cs.

I can define other layers like data layer, business layer, etc. but the problem I am facing is:

How to add Middleware layer in Azure Functions (Microsoft.NET.Sdk.Functions) application?

One solution I feel might be we can add a program.cs file to the project which will have a main method? My doubt is can we add Program.cs file to this project, what could be the implications?

Or is their a way to use Startup.cs to configure middlewares?

Why this doubt of adding Program.cs file came to my mind is because, all the online examples I am seeing is for Isolated Azure Function. and their is no reference of HttpTrigger function, so is it correct to add a program.cs to HttpTrigger function project.

I have already added Startup.cs for dependency Injection.

enter image description here

enter image description here

Moho

The Azure Functions application must use the isolated process, in which case you use the HostBulder.AddMiddleware<T> method to add middleware when configuring the function worker:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults( builder =>
    {
        builder.AddApplicationInsights()
            .AddApplicationInsightsLogger()

            .UseMiddleware<YourMiddleweare>()
    } )
    .ConfigureServices( services =>
    {
        ... add services to DI container here ...
    }
    .Build();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add Middleware in Azure HttpTrigger Functions (Microsoft.NET.Sdk.Functions) in .net

Azure Function v2 references a project with a higher version of Newtonsoft.Json than Microsoft.NET.Sdk.Functions

How to utilize a .NET SDK inside Azure Function App?

Version conflict caused by Microsoft.NET.Sdk.Functions

Build Error after Upgrading microsoft.net.sdk.functions

How can I do ModelBinding with HttpTrigger in Azure Functions?

How to list all the functions in an Azure Function App

In Azure Functions, can I combine a C# HttpTrigger with a Python HttpTrigger

VS2019 cannot load the project due to missing NuGet Microsoft.NET.Sdk.Functions package, but cannot add this package either

Custom routing in Azure functions using HttpTrigger attribute

Issue with returning JArray from Azure Functions HttpTrigger

How do you access .NET Framework default SMTP service in Azure Functions? Using Postal in Azure Function

How can I add SSH.NET NuGet packages into my Azure Functions v2.0?

how to include the azure sdk for azure nodejs functions?

Azure Function App - How to upgrade .NET runtime

How to add Azure Functions extension

How to migrate Azure Functions v3 to .net core 5.0

How to Implement Singleton (or shared resources) in Azure .Net 5 Isolated Functions?

How to call Microsoft Graph from Azure Functions

VB.NET Azure Functions — what does the Microsoft.CSharp assembly do?

Azure Functions/.NET7: Could not load file or assembly 'Microsoft.Extensions.Caching.Memory, Version=7.0.0.0

Remove several functions from Azure Function App

Functions not showing up in Azure Function App

Azure Function APP [Expose functions key]

How to delay process using Azure functions?

How to fix ImportError with 'EventGridPublisherClient' in Azure HTTPTrigger function?

No job functions found in Azure Functions project (.NET standard 2.0) local

Creating Azure Functions Targeting .NET 7

Azure Functions - System.Net.Http