Sergii Zhuravskyi
Sergii Zhuravskyi

Reputation: 4368

Should I use Microsoft.AspNetCore.Mvc package in Azure isolated function? what are the disadvantages and advantages?

It looks like Microsoft recomendation is to use azure isolated functions over in process functions . If you open Azure functions road map you can see that isolated functions are the only option after .net 8 https://techcommunity.microsoft.com/t5/apps-on-azure-blog/net-on-azure-functions-roadmap/ba-p/2197916 .

We started working with isolated functions(http triger), however we found that there are alot of limitation and slight package missmatch between inprocess and isolated functions. More details can be found by this link https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-differences .

Moreover, there is a difference in available API for azure function and Asp.net API.

The first differences for me is the fact that by default I have to work with HttpRequestData and HttpResponseData classes.

There are following packages in Nuget repository https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Abstractions https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Core

These packages would allow me to use IActionResult in Azure Function. That in turn would make working with a http trigger function feel like working with an ASP.net API.

My question is: what are disadvantages and advantages of pulling these packages as a dependency into an Isolated azure function ?

Note: I more concerned about disadvantages, Advantages are kind of obvious we can use familiar classes. It looks like asp net pachage handels UserClaims better. However, if you can list more advantages that would be great.

Upvotes: 2

Views: 1128

Answers (1)

Jeff McCrory
Jeff McCrory

Reputation: 26

.Net 7 works exclusively using the isolated process for function apps and the Microsoft.Azure.Functions.Worker.Http library.

You cannot use Microsoft.AspNetCore.Mvc with .Net 7 function apps.

Even if you add Microsoft.AspNetCore.Mvc via a nuget (which you DO have to do with .Net 7 function app) and wire up your function to use HttpRequest it won't work, its just set to null on the function call... screenshot of .Net 7 function app using HttpRequest

You have acccess to the FunctionContext via the HttpRequestData object, but that still won't give you user claims like MVC HttpContext. If you want to extract them from the authorization header you'd have to write middleware to do so like the example here: https://adamstorr.azurewebsites.net/blog/using-azure-functions-middleware-to-access-claimsprincipal-in-azure-static-web-apps

Upvotes: 1

Related Questions