Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/DotNetCore/AzureFunctions/AzureFunctions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.35828.13 main
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionAppIsolated", "FunctionAppIsolated\FunctionAppIsolated.csproj", "{B24FEE1E-DDB8-E1CD-925F-199BF3D603C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B24FEE1E-DDB8-E1CD-925F-199BF3D603C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B24FEE1E-DDB8-E1CD-925F-199BF3D603C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B24FEE1E-DDB8-E1CD-925F-199BF3D603C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B24FEE1E-DDB8-E1CD-925F-199BF3D603C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DBF3FBCB-A4CD-41A8-BA2D-562B632F5BE7}
EndGlobalSection
EndGlobal
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 examples/DotNetCore/AzureFunctions/FunctionAppIsolated/Program.cs
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();
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}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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.Anonymous, "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).");
}
}
}
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.Anonymous, "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.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}