CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2025-05-08
by Pavan

Original Post

Original - Posted on 2024-04-04
by Vivek Vaibhav Shandilya



            
Present in both answers; Present only in the new answer; Present only in the old answer;

> how to configure Swagger for Azure Functions on .NET 8 in the isolated worker model?
I have configured swagger with .NET 8.0 isolated worker model in Http trigger function.
Must be add below packages in project file ``` <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.16.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.6.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.0" /> ```
**Function.cs:** ``` public class JobFunction { private readonly ILogger<JobFunction> _logger;
public JobFunction(ILogger<JobFunction> logger) { _logger = logger; }
[Function("v1-job-selectAll")] [OpenApiOperation(operationId: "selectAllJobs", tags: new[] { "TctJob" })] [OpenApiParameter(name: "agentId", In = ParameterLocation.Query, Required = true, Type = typeof(Guid), Description = "The id of the agent.")] [OpenApiRequestBody("application/json", typeof(string), Description = "Request body.")] [OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", typeof(string), Description = "Job list.")] [OpenApiResponseWithoutBody(HttpStatusCode.BadRequest, Description = "Invalid ID.")] public HttpResponseData Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "v1/job/selectAll/{agentId}")] HttpRequestData req) { _logger.LogInformation("Processing request for job list."); var response = req.CreateResponse(HttpStatusCode.OK); response.WriteString("Job list returned."); return response; } } ``` Below packages which i have used.
``` <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> <!-- Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4. --> <!-- <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> --> <!-- <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" /> --> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" /> <PackageReference Include="Microsoft.OpenApi" Version="1.6.24" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.16.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.6.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <ItemGroup> <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> </ItemGroup> </Project> ``` **Program.cs:** ``` using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions; using Microsoft.Extensions.Hosting;
var host = new HostBuilder() .ConfigureFunctionsWebApplication(worker => worker.UseNewtonsoftJson()) .ConfigureOpenApi() // Required for OpenAPI generation .Build();
host.Run(); ``` By using configuration and code able to run the function successfully.
**Output:**
![enter image description here](https://i.sstatic.net/AJoBk6W8.png%29%5D)

![enter image description here](https://i.sstatic.net/nSmgjQDP.png%29%5D)
You can use the same method in `Isolated-process` model.
This worked for me.
```csharp using System; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options;
namespace FunctionApp16 { public class Function2 { private readonly ILogger<Function2> _logger;
public Function2(ILogger<Function2> logger) { _logger = logger; }
[Function(nameof(Function2))] public void Run([BlobTrigger("%StorageContainer:SourceImages%", Connection = "AzureWebJobsStorage")] string message) { _logger.LogInformation($"C# Queue trigger function processed: {message}"); } } } ``` **`FunctionApp16.csproj`:** ```xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" /> <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.3.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <ItemGroup> <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> </ItemGroup> </Project> ``` **`Program.cs`:**
```csharp using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;
var host = new HostBuilder() .ConfigureFunctionsWebApplication() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build();
host.Run();
```
**`local.settings.json`:** ``` { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", "StorageContainer:SourceImages": "test" } } ```
### `OUTPUT`:
[![][1]][1]
[1]: https://i.imgur.com/JvX7CiG.png

        
Present in both answers; Present only in the new answer; Present only in the old answer;