-
Notifications
You must be signed in to change notification settings - Fork 80
Add Function App example with .NET 8 isolated model #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,37 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.1.31904.369 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionApp", "FunctionApp\FunctionApp.csproj", "{8C4BCA4B-3413-4757-A27A-CD19319BB84E}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionAppIsolatedMode", "FunctionAppIsolatedMode\FunctionAppIsolatedMode.csproj", "{1F856589-317F-4708-B6D8-491EA899FEC0}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {84007F82-034B-4153-A3A6-A3EB0DEA748F} | ||
| EndGlobalSection | ||
| EndGlobal | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.1.31904.369 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionApp", "FunctionApp\FunctionApp.csproj", "{8C4BCA4B-3413-4757-A27A-CD19319BB84E}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionAppIsolatedMode", "FunctionAppIsolatedMode\FunctionAppIsolatedMode.csproj", "{1F856589-317F-4708-B6D8-491EA899FEC0}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionAppIsolated", "FunctionAppIsolated\FunctionAppIsolated.csproj", "{53FD72EC-18AA-4BF0-B821-650CEF06FA1C}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {8C4BCA4B-3413-4757-A27A-CD19319BB84E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {1F856589-317F-4708-B6D8-491EA899FEC0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {53FD72EC-18AA-4BF0-B821-650CEF06FA1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {53FD72EC-18AA-4BF0-B821-650CEF06FA1C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {53FD72EC-18AA-4BF0-B821-650CEF06FA1C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {53FD72EC-18AA-4BF0-B821-650CEF06FA1C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {84007F82-034B-4153-A3A6-A3EB0DEA748F} | ||
| EndGlobalSection | ||
| EndGlobal |
32 changes: 32 additions & 0 deletions
32
examples/DotNetCore/AzureFunction/FunctionAppIsolated/FunctionAppIsolated.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <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="Azure.Identity" Version="1.13.2" /> | ||
| <PackageReference Include="Microsoft.Azure.AppConfiguration.Functions.Worker" Version="8.1.1" /> | ||
| <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" /> | ||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" /> | ||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.1" /> | ||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.5.0" /> | ||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.1" /> | ||
| <PackageReference Include="Microsoft.FeatureManagement" Version="4.0.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> |
37 changes: 37 additions & 0 deletions
37
examples/DotNetCore/AzureFunction/FunctionAppIsolated/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using Azure.Identity; | ||
| using Microsoft.Azure.Functions.Worker.Builder; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.FeatureManagement; | ||
|
|
||
| var builder = FunctionsApplication.CreateBuilder(args); | ||
|
|
||
| // Connect to Azure App Configuration | ||
| builder.Configuration.AddAzureAppConfiguration(options => | ||
| { | ||
| Uri endpoint = new(Environment.GetEnvironmentVariable("AZURE_APPCONFIG_ENDPOINT") ?? string.Empty); | ||
| options.Connect(endpoint, new DefaultAzureCredential()) | ||
| // Load all keys that start with `TestApp:` and have no label | ||
| .Select("TestApp:*") | ||
| // Reload configuration if any selected key-values have changed. | ||
| // Use the default refresh interval of 30 seconds. It can be overridden via AzureAppConfigurationRefreshOptions.SetRefreshInterval. | ||
| .ConfigureRefresh(refreshOptions => | ||
| { | ||
| refreshOptions.RegisterAll(); | ||
| }) | ||
| // Load all feature flags with no label. To load feature flags with specific keys and labels, set via FeatureFlagOptions.Select. | ||
| // Use the default refresh interval of 30 seconds. It can be overridden via FeatureFlagOptions.SetRefreshInterval. | ||
| .UseFeatureFlags(); | ||
| }); | ||
|
|
||
| // Add Azure App Configuration middleware and feature management to the service collection. | ||
| builder.Services | ||
| .AddAzureAppConfiguration() | ||
| .AddFeatureManagement(); | ||
|
|
||
| // Use Azure App Configuration middleware for dynamic configuration and feature flag refresh. | ||
| builder.UseAzureAppConfiguration(); | ||
|
|
||
| builder.ConfigureFunctionsWebApplication(); | ||
|
|
||
| builder.Build().Run(); |
27 changes: 27 additions & 0 deletions
27
examples/DotNetCore/AzureFunction/FunctionAppIsolated/ReadQueuedMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using Azure.Storage.Queues.Models; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace FunctionAppIsolated | ||
| { | ||
| public class ReadQueuedMessage | ||
| { | ||
| private readonly ILogger<ReadQueuedMessage> _logger; | ||
|
|
||
| public ReadQueuedMessage(ILogger<ReadQueuedMessage> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| // Queue triggered function with queue name defined in Azure App Configuration. | ||
| // The queue name is stored with the key `TestApp:Storage:QueueName` in Azure App Configuration. | ||
| // `AZURE_APPCONFIG_REFERENCE_QUEUENAME` is an app setting of the Function App referencing this key. | ||
| // Learn more about App Configuration Reference: | ||
| // https://learn.microsoft.com/azure/app-service/app-service-configuration-references | ||
| [Function(nameof(ReadQueuedMessage))] | ||
| public void Run([QueueTrigger(queueName: "%AZURE_APPCONFIG_REFERENCE_QUEUENAME%")] QueueMessage message) | ||
| { | ||
| _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}"); | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
examples/DotNetCore/AzureFunction/FunctionAppIsolated/ShowBetaFeature.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.FeatureManagement; | ||
|
|
||
| namespace FunctionAppIsolated | ||
| { | ||
| public class ShowBetaFeature | ||
| { | ||
| private readonly IVariantFeatureManagerSnapshot _featureManager; | ||
| private readonly ILogger<ShowBetaFeature> _logger; | ||
|
|
||
| public ShowBetaFeature(IVariantFeatureManagerSnapshot featureManager, ILogger<ShowBetaFeature> logger) | ||
| { | ||
| _featureManager = featureManager; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| [Function("ShowBetaFeature")] | ||
| public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req) | ||
| { | ||
| _logger.LogInformation("C# HTTP trigger function processed a request."); | ||
|
|
||
| // Read feature flag | ||
| string featureName = "Beta"; | ||
| bool featureEnabled = await _featureManager.IsEnabledAsync(featureName); | ||
|
|
||
| return new OkObjectResult(featureEnabled | ||
| ? $"{featureName} feature is On" | ||
| : $"{featureName} feature is Off (or not found in Azure App Configuration)."); | ||
|
|
||
| } | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
examples/DotNetCore/AzureFunction/FunctionAppIsolated/ShowMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace FunctionAppIsolated | ||
| { | ||
| public class ShowMessage | ||
| { | ||
| private readonly IConfiguration _configuration; | ||
| private readonly ILogger<ShowMessage> _logger; | ||
|
|
||
| public ShowMessage(IConfiguration configuration, ILogger<ShowMessage> logger) | ||
| { | ||
| _configuration = configuration; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| [Function("ShowMessage")] | ||
| public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req) | ||
| { | ||
| _logger.LogInformation("C# HTTP trigger function processed a request."); | ||
|
|
||
| // Read configuration data | ||
| string key = "TestApp:Settings:Message"; | ||
| string? message = _configuration[key]; | ||
|
|
||
| return new OkObjectResult(message ?? $"Please create a key-value with the key '{key}' in Azure App Configuration."); | ||
| } | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
examples/DotNetCore/AzureFunction/FunctionAppIsolated/host.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "version": "2.0" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra empty line