From 34a1895eee0a9cf1830f384a07be25aff32fb5d9 Mon Sep 17 00:00:00 2001
From: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
Date: Fri, 19 Jul 2024 00:50:59 +0800
Subject: [PATCH 01/15] version bump 3.5.0 (#475)
---
.../Microsoft.FeatureManagement.AspNetCore.csproj | 2 +-
.../Microsoft.FeatureManagement.csproj | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Microsoft.FeatureManagement.AspNetCore/Microsoft.FeatureManagement.AspNetCore.csproj b/src/Microsoft.FeatureManagement.AspNetCore/Microsoft.FeatureManagement.AspNetCore.csproj
index 7e6b3226..c14d391f 100644
--- a/src/Microsoft.FeatureManagement.AspNetCore/Microsoft.FeatureManagement.AspNetCore.csproj
+++ b/src/Microsoft.FeatureManagement.AspNetCore/Microsoft.FeatureManagement.AspNetCore.csproj
@@ -4,7 +4,7 @@
3
- 4
+ 5
0
diff --git a/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj b/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
index 95e64f26..62e3ed9d 100644
--- a/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
+++ b/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
@@ -4,7 +4,7 @@
3
- 4
+ 5
0
From d069049c70f84b429f5232765cad08dfb4ca00f8 Mon Sep 17 00:00:00 2001
From: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
Date: Tue, 23 Jul 2024 13:56:34 +0800
Subject: [PATCH 02/15] fix typo in comment (#480)
---
.../Telemetry/VariantAssignmentReason.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Microsoft.FeatureManagement/Telemetry/VariantAssignmentReason.cs b/src/Microsoft.FeatureManagement/Telemetry/VariantAssignmentReason.cs
index a4db27d4..0e2ce56a 100644
--- a/src/Microsoft.FeatureManagement/Telemetry/VariantAssignmentReason.cs
+++ b/src/Microsoft.FeatureManagement/Telemetry/VariantAssignmentReason.cs
@@ -9,7 +9,7 @@ namespace Microsoft.FeatureManagement.Telemetry
public enum VariantAssignmentReason
{
///
- /// Variant allocation did not happend. No variant is assigned.
+ /// Variant allocation did not happen. No variant is assigned.
///
None,
From de9eeed4f0149eff1613fdf284b934ddab09657f Mon Sep 17 00:00:00 2001
From: Amer Jusupovic <32405726+amerjusupovic@users.noreply.github.com>
Date: Thu, 25 Jul 2024 13:29:53 -0700
Subject: [PATCH 03/15] Use GitHub workflow for PR builds (#481)
* add github workflow ci.yml, remove old pipelines
* test workflow failure
* revert test
---
.github/workflows/ci.yml | 53 +++++++++
.pipelines/OneBranch.Official.yml | 175 ------------------------------
.pipelines/windows-buddy.yml | 125 ---------------------
3 files changed, 53 insertions(+), 300 deletions(-)
create mode 100644 .github/workflows/ci.yml
delete mode 100644 .pipelines/OneBranch.Official.yml
delete mode 100644 .pipelines/windows-buddy.yml
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 00000000..3701da6c
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,53 @@
+name: FeatureManagement-Dotnet CI
+
+on:
+ push:
+ branches:
+ - main
+ - preview
+ - release/*
+ pull_request:
+ branches:
+ - main
+ - preview
+ - release/*
+
+permissions:
+ security-events: write
+
+jobs:
+ build:
+ runs-on: windows-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Install .NET
+ run: pwsh build/install-dotnet.ps1 -RestoreOnly
+
+ - name: Restore
+ run: pwsh build.ps1 -RestoreOnly
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v3
+ with:
+ languages: 'csharp'
+
+ - name: Dotnet Build
+ run: pwsh build.ps1
+
+ - name: Dotnet Pack
+ run: pwsh pack.ps1
+
+ - name: Dotnet Test
+ run: pwsh test.ps1
+
+ - name: Publish Test Results
+ uses: actions/upload-artifact@v4
+ with:
+ name: Unit Test Results
+ path: ${{ github.workspace }}/tests/**/*.trx
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v3
diff --git a/.pipelines/OneBranch.Official.yml b/.pipelines/OneBranch.Official.yml
deleted file mode 100644
index 15c44d0e..00000000
--- a/.pipelines/OneBranch.Official.yml
+++ /dev/null
@@ -1,175 +0,0 @@
-trigger: none
-
-parameters: # parameters are shown up in ADO UI in a build queue time
-- name: 'debug'
- displayName: 'Enable debug output'
- type: boolean
- default: false
-
-variables:
- CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task
- system.debug: ${{ parameters.debug }}
- ENABLE_PRS_DELAYSIGN: 1
- ROOT: $(Build.SourcesDirectory)
- REPOROOT: $(Build.SourcesDirectory)
- OUTPUTROOT: $(REPOROOT)\out
- CDP_USER_SOURCE_FOLDER_CONTAINER_PATH: $(Build.SourcesDirectory)
- CDP_DEFINITION_BUILD_COUNT_DAY: $[counter(format('{0:yyyyMMdd}', pipeline.startTime), 1)]
- CDP_DEFINITION_BUILD_COUNT_MONTH: $[counter(format('{0:yyyyMM}', pipeline.startTime), 1)]
- CDP_DEFINITION_BUILD_COUNT_YEAR: $[counter(format('{0:yyyy}', pipeline.startTime), 1)]
- NUGET_XMLDOC_MODE: none
-
- # Docker image which is used to build the project
- WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest'
-
-resources:
- repositories:
- - repository: templates
- type: git
- name: OneBranch.Pipelines/GovernedTemplates
- ref: refs/heads/main
-
-extends:
- template: v2/OneBranch.Official.CrossPlat.yml@templates
- parameters:
- cloudvault:
- enabled: false
- globalSdl:
- tsa:
- enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode.
- # credscan:
- # suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json
- binskim:
- break: true # always break the build on binskim issues in addition to TSA upload
- policheck:
- break: true # always break the build on policheck issues. You can disable it by setting to 'false'
- # baseline:
- # baselineFile: $(Build.SourcesDirectory)\.gdn\global.gdnbaselines
- cg:
- failOnAlert: false
-
- stages:
- - stage: build
- jobs:
- - job: main
- pool:
- type: windows
-
- variables:
- ob_outputDirectory: '$(REPOROOT)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault
- ob_sdl_binskim_break: true
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: # conditionally enable symbolsPublishing for master branch only
- ob_symbolsPublishing_enabled: true
- # ob_sdl_baseline_baselineFile: $(Build.SourcesDirectory)\.gdn\build.official.gdnbaselines
- # ob_sdl_codeSignValidation_excludes: -|**\*.js # Example -|**\*.js;-|**\Test*\**
- ob_artifactBaseName: 'drop'
- ob_sdl_cg_failOnAlert: false
-
- steps:
- - task: CmdLine@2
- displayName: 'Install .NET'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd build/install-dotnet.ps1 -RestoreOnly
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CmdLine@2
- displayName: 'Restore'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd build.ps1 -RestoreOnly
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: onebranch.pipeline.version@1 # generates automatic version
- displayName: 'Setup BuildNumber'
- inputs:
- system: 'BuildRevision'
- major: '1'
- minor: '0'
- name: 'FeatureManagement-Dotnet'
- # exclude_commit: true
-
-
-
- - task: CmdLine@2
- displayName: 'Dotnet Build'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd build.ps1
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\buildlogs'
- Contents: |
- **/*
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\build\Build Logs'
-
-
-
- - task: onebranch.pipeline.signing@1
- displayName: 'Signing'
- inputs:
- command: 'sign'
- signing_environment: 'azure-ado'
- signing_profile: 'external_distribution '
- files_to_sign: '*/bin/Release/**/*'
- search_root: '$(Build.SourcesDirectory)\src'
-
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\src'
- Contents: |
- */bin/Release/**/*
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\build\Binaries'
-
- - task: CmdLine@2
- displayName: 'Dotnet Pack'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd pack.ps1
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\buildlogs'
- Contents: |
- **/*
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\package\Build Logs'
-
-
-
- - task: onebranch.pipeline.signing@1
- displayName: 'Signing'
- inputs:
- command: 'sign'
- signing_environment: 'azure-ado'
- signing_profile: 'external_distribution '
- files_to_sign: '*/bin/PackageOutput/**/*.nupkg'
- search_root: '$(Build.SourcesDirectory)\src'
-
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\src'
- Contents: |
- */bin/PackageOutput/**/*.nupkg
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\package\Packages'
-
- - task: CmdLine@2
- displayName: 'Dotnet Test'
- inputs:
- script: '$(Build.SourcesDirectory)\build/CallPowerShell.cmd test.ps1|| exit /b 0'
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\tests'
- Contents: '**/*.trx'
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\test\_post_command__run_log_alerts_schedular_tests\_testresults'
-
- - task: PublishTestResults@2
- displayName: 'Unit Tests'
- inputs:
- testResultsFormat: 'vstest'
- testResultsFiles: '**/*.trx'
- searchFolder: ''
- failTaskOnFailedTests: False
- testRunTitle: Unit Tests
\ No newline at end of file
diff --git a/.pipelines/windows-buddy.yml b/.pipelines/windows-buddy.yml
deleted file mode 100644
index 48e9a699..00000000
--- a/.pipelines/windows-buddy.yml
+++ /dev/null
@@ -1,125 +0,0 @@
-
-pr:
-- main
-- release/*
-
-trigger:
-- none
-
-parameters: # parameters are shown up in ADO UI in a build queue time
-- name: 'debug'
- displayName: 'Enable debug output'
- type: boolean
- default: false
-
-jobs:
-- job: main
- pool:
- type: windows
- isCustom: true
- name: Azure Pipelines
- vmImage: 'windows-latest'
-
- variables:
- Codeql.Enabled: true
-
- steps:
- - task: AntiMalware@4
- inputs:
- InputType: 'Basic'
- ScanType: 'CustomScan'
- FileDirPath: '$(Build.StagingDirectory)'
- TreatSignatureUpdateFailureAs: 'Warning'
- SignatureFreshness: 'UpToDate'
- TreatStaleSignatureAs: 'Error'
-
- - task: CredScan@3
-
- - task: nuget-security-analysis@0
-
- - task: CmdLine@2
- displayName: 'Install .NET'
- inputs:
- script: build\CallPowerShell.cmd build/install-dotnet.ps1 -RestoreOnly
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CmdLine@2
- displayName: 'Restore'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd build.ps1 -RestoreOnly
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CodeQL3000Init@0
- displayName: 'Initialize CodeQL'
-
- - task: CmdLine@2
- displayName: 'Dotnet Build'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd build.ps1
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\buildlogs'
- Contents: |
- **/*
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\build\Build Logs'
-
- - task: CmdLine@2
- displayName: 'Dotnet Pack'
- inputs:
- script: $(Build.SourcesDirectory)\build\CallPowerShell.cmd pack.ps1
- workingDirectory: '$(Build.SourcesDirectory)'
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\buildlogs'
- Contents: |
- **/*
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\package\Build Logs'
-
- - task: CmdLine@2
- displayName: 'Dotnet Test'
- inputs:
- script: '$(Build.SourcesDirectory)\build/CallPowerShell.cmd test.ps1|| exit /b 0'
- workingDirectory: '$(Build.SourcesDirectory)'
-
-
- - task: CopyFiles@2
- inputs:
- SourceFolder: '$(Build.SourcesDirectory)\tests'
- Contents: '**/*.trx'
- TargetFolder: '$(Build.SourcesDirectory)\out\outputs\test\_post_command__run_log_alerts_schedular_tests\_testresults'
-
- - task: PublishTestResults@2
- displayName: 'Unit Tests'
- inputs:
- testResultsFormat: 'vstest'
- testResultsFiles: '**/*.trx'
- searchFolder: ''
- failTaskOnFailedTests: True
- testRunTitle: Unit Tests
-
- - task: ComponentGovernanceComponentDetection@0
- displayName: "Component Detection"
- inputs:
- scanType: 'Register'
- verbosity: 'Verbose'
- alertWarningLevel: 'High'
-
- - task: BinSkim@4
- inputs:
- InputType: 'Basic'
- Function: 'analyze'
- TargetPattern: 'guardianGlob'
- AnalyzeTargetGlob: '$(Build.SourcesDirectory)\**.dll;$(Build.SourcesDirectory)\**.exe;'
-
- - task: PublishPipelineArtifact@1
- displayName: 'Publish Artifacts'
- inputs:
- targetPath: '$(Build.SourcesDirectory)\out\outputs'
- artifact: 'drop'
- publishLocation: 'pipeline'
-
- - task: CodeQL3000Finalize@0
- displayName: 'Finalize CodeQL'
From 3b838a4dae264f857bb9ebbe1220b179603ceb8d Mon Sep 17 00:00:00 2001
From: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
Date: Fri, 16 Aug 2024 01:21:27 +0800
Subject: [PATCH 04/15] use TimeProvider (#452)
---
.../FeatureFilters/ISystemClock.cs | 20 -------------------
.../FeatureFilters/TimeWindowFilter.cs | 6 +++---
.../Microsoft.FeatureManagement.csproj | 3 ++-
.../Tests.FeatureManagement/OnDemandClock.cs | 10 +++++++---
4 files changed, 12 insertions(+), 27 deletions(-)
delete mode 100644 src/Microsoft.FeatureManagement/FeatureFilters/ISystemClock.cs
diff --git a/src/Microsoft.FeatureManagement/FeatureFilters/ISystemClock.cs b/src/Microsoft.FeatureManagement/FeatureFilters/ISystemClock.cs
deleted file mode 100644
index 1fc9b667..00000000
--- a/src/Microsoft.FeatureManagement/FeatureFilters/ISystemClock.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) Microsoft Corporation.
-// Licensed under the MIT license.
-//
-
-using System;
-
-namespace Microsoft.FeatureManagement.FeatureFilters
-{
- ///
- /// Abstracts the system clock to facilitate testing.
- /// .NET8 offers an abstract class TimeProvider. After we stop supporting .NET version less than .NET8, this ISystemClock should retire.
- ///
- internal interface ISystemClock
- {
- ///
- /// Retrieves the current system time in UTC.
- ///
- public DateTimeOffset UtcNow { get; }
- }
-}
diff --git a/src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs b/src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs
index fb1f6f01..62b5f4a5 100644
--- a/src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs
+++ b/src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs
@@ -39,7 +39,7 @@ public TimeWindowFilter(ILoggerFactory loggerFactory = null)
///
/// This property allows the time window filter in our test suite to use simulated time.
///
- internal ISystemClock SystemClock { get; set; }
+ internal TimeProvider SystemClock { get; set; }
///
/// Binds configuration representing filter parameters to .
@@ -74,7 +74,7 @@ public Task EvaluateAsync(FeatureFilterEvaluationContext context)
// Check if prebound settings available, otherwise bind from parameters.
TimeWindowFilterSettings settings = (TimeWindowFilterSettings)context.Settings ?? (TimeWindowFilterSettings)BindParameters(context.Parameters);
- DateTimeOffset now = SystemClock?.UtcNow ?? DateTimeOffset.UtcNow;
+ DateTimeOffset now = SystemClock?.GetUtcNow() ?? DateTimeOffset.UtcNow;
if (!settings.Start.HasValue && !settings.End.HasValue)
{
@@ -129,7 +129,7 @@ public Task EvaluateAsync(FeatureFilterEvaluationContext context)
private DateTimeOffset? ReloadClosestStart(TimeWindowFilterSettings settings)
{
- DateTimeOffset now = SystemClock?.UtcNow ?? DateTimeOffset.UtcNow;
+ DateTimeOffset now = SystemClock?.GetUtcNow() ?? DateTimeOffset.UtcNow;
DateTimeOffset? closestStart = RecurrenceEvaluator.CalculateClosestStart(now, settings);
diff --git a/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj b/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
index 62e3ed9d..3abf1568 100644
--- a/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
+++ b/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj
@@ -35,10 +35,11 @@
-
+
+
diff --git a/tests/Tests.FeatureManagement/OnDemandClock.cs b/tests/Tests.FeatureManagement/OnDemandClock.cs
index c639a3e3..59c8c0d8 100644
--- a/tests/Tests.FeatureManagement/OnDemandClock.cs
+++ b/tests/Tests.FeatureManagement/OnDemandClock.cs
@@ -1,10 +1,14 @@
-using Microsoft.FeatureManagement.FeatureFilters;
-using System;
+using System;
namespace Tests.FeatureManagement
{
- class OnDemandClock : ISystemClock
+ class OnDemandClock : TimeProvider
{
public DateTimeOffset UtcNow { get; set; }
+
+ public override DateTimeOffset GetUtcNow()
+ {
+ return UtcNow;
+ }
}
}
From 882c7b74357304bf799abede2c98577724343985 Mon Sep 17 00:00:00 2001
From: Ross Grambo
Date: Fri, 23 Aug 2024 10:27:41 -0700
Subject: [PATCH 05/15] Adjusts builder extension methods to be friendlier
(#487)
* Adds and adjusts builder extension methods
* Removed UseFeatureManagement and adjusted name of AddAppInsightsTelemetryPublisher
* Adjusts examples
---
examples/EvaluationDataToApplicationInsights/Program.cs | 2 +-
examples/VariantServiceDemo/Program.cs | 2 +-
.../AspNetCoreFeatureManagementBuilderExtensions.cs | 8 ++++++++
.../FeatureManagementBuilderExtensions.cs | 8 ++++++--
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/examples/EvaluationDataToApplicationInsights/Program.cs b/examples/EvaluationDataToApplicationInsights/Program.cs
index bf83d5d6..dbc856fc 100644
--- a/examples/EvaluationDataToApplicationInsights/Program.cs
+++ b/examples/EvaluationDataToApplicationInsights/Program.cs
@@ -30,7 +30,7 @@
// Wire up evaluation event emission
builder.Services.AddFeatureManagement()
.WithTargeting()
- .AddApplicationInsightsTelemetryPublisher();
+ .AddApplicationInsightsTelemetry();
//
// Default code from .NET template below
diff --git a/examples/VariantServiceDemo/Program.cs b/examples/VariantServiceDemo/Program.cs
index 843cd1ce..8ac9a031 100644
--- a/examples/VariantServiceDemo/Program.cs
+++ b/examples/VariantServiceDemo/Program.cs
@@ -37,7 +37,7 @@
builder.Services.AddFeatureManagement()
.WithTargeting()
.WithVariantService("Calculator")
- .AddApplicationInsightsTelemetryPublisher();
+ .AddApplicationInsightsTelemetry();
var app = builder.Build();
diff --git a/src/Microsoft.FeatureManagement.AspNetCore/AspNetCoreFeatureManagementBuilderExtensions.cs b/src/Microsoft.FeatureManagement.AspNetCore/AspNetCoreFeatureManagementBuilderExtensions.cs
index 9091a4b0..43aa6b46 100644
--- a/src/Microsoft.FeatureManagement.AspNetCore/AspNetCoreFeatureManagementBuilderExtensions.cs
+++ b/src/Microsoft.FeatureManagement.AspNetCore/AspNetCoreFeatureManagementBuilderExtensions.cs
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -55,6 +57,12 @@ public static IFeatureManagementBuilder UseDisabledFeaturesHandler(this IFeature
/// A that can be used to customize feature management functionality.
public static IFeatureManagementBuilder WithTargeting(this IFeatureManagementBuilder builder)
{
+ // Add HttpContextAccessor if it doesn't already exist
+ if (!builder.Services.Any(service => service.ServiceType == typeof(IHttpContextAccessor)))
+ {
+ builder.Services.AddHttpContextAccessor();
+ }
+
//
// Register the targeting context accessor with the same lifetime as the feature manager
if (builder.Services.Any(descriptor => descriptor.ServiceType == typeof(IFeatureManager) && descriptor.Lifetime == ServiceLifetime.Scoped))
diff --git a/src/Microsoft.FeatureManagement.Telemetry.ApplicationInsights/FeatureManagementBuilderExtensions.cs b/src/Microsoft.FeatureManagement.Telemetry.ApplicationInsights/FeatureManagementBuilderExtensions.cs
index 002d2bfc..503f4776 100644
--- a/src/Microsoft.FeatureManagement.Telemetry.ApplicationInsights/FeatureManagementBuilderExtensions.cs
+++ b/src/Microsoft.FeatureManagement.Telemetry.ApplicationInsights/FeatureManagementBuilderExtensions.cs
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
+using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.FeatureManagement.Telemetry.ApplicationInsights;
@@ -13,11 +15,11 @@ namespace Microsoft.FeatureManagement
public static class FeatureManagementBuilderExtensions
{
///
- /// Adds the using to the feature management builder.
+ /// Adds the and the using to the feature management builder.
///
/// The feature management builder.
/// The feature management builder.
- public static IFeatureManagementBuilder AddApplicationInsightsTelemetryPublisher(this IFeatureManagementBuilder builder)
+ public static IFeatureManagementBuilder AddApplicationInsightsTelemetry(this IFeatureManagementBuilder builder)
{
if (builder == null)
{
@@ -29,6 +31,8 @@ public static IFeatureManagementBuilder AddApplicationInsightsTelemetryPublisher
throw new ArgumentException($"The provided builder's services must not be null.", nameof(builder));
}
+ builder.Services.AddSingleton();
+
builder.Services.AddSingleton();
if (!builder.Services.Any((ServiceDescriptor d) => d.ServiceType == typeof(IHostedService) && d.ImplementationType == typeof(ApplicationInsightsHostedService)))
From 9284d276930395d6b8cb06c2fb7c3a96dc23df69 Mon Sep 17 00:00:00 2001
From: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
Date: Mon, 26 Aug 2024 11:06:13 +0800
Subject: [PATCH 06/15] Use ITargetingContext when calling GetVariantAsync
(#484)
* add variant feature manager extensions
* use TContext to avoid future breaking change
* TargetingContext in EvaluationEvent
* update comments & not use ambient context in contextual case
* update comment
* use ITargetingContext & check runtime context type
* use TargetingCotnext for private method
* use var instead of type
* revert change on ContextualTestFilter
* update comment
* update comment
---
.../FeatureManager.cs | 30 +++++++-----
.../FeatureManagerSnapshot.cs | 2 +-
.../IFeatureManager.cs | 2 +-
.../IVariantFeatureManager.cs | 6 +--
.../VariantFeatureManagerExtensions.cs | 28 +++++++++++
tests/Tests.FeatureManagement/AppContext.cs | 9 +++-
.../FeatureManagementTest.cs | 49 ++++++++++++++++++-
tests/Tests.FeatureManagement/Features.cs | 1 +
.../Tests.FeatureManagement/appsettings.json | 28 +++++++++++
9 files changed, 135 insertions(+), 20 deletions(-)
create mode 100644 src/Microsoft.FeatureManagement/VariantFeatureManagerExtensions.cs
diff --git a/src/Microsoft.FeatureManagement/FeatureManager.cs b/src/Microsoft.FeatureManagement/FeatureManager.cs
index 40a0f0a7..d9e8a99d 100644
--- a/src/Microsoft.FeatureManagement/FeatureManager.cs
+++ b/src/Microsoft.FeatureManagement/FeatureManager.cs
@@ -144,7 +144,7 @@ public async Task IsEnabledAsync(string feature)
/// Checks whether a given feature is enabled.
///
/// The name of the feature to check.
- /// A context providing information that can be used to evaluate whether a feature should be on or off.
+ /// A context that provides information to evaluate whether a feature should be on or off.
/// True if the feature is enabled, otherwise false.
public async Task IsEnabledAsync(string feature, TContext appContext)
{
@@ -170,7 +170,7 @@ public async ValueTask IsEnabledAsync(string feature, CancellationToken ca
/// Checks whether a given feature is enabled.
///
/// The name of the feature to check.
- /// A context providing information that can be used to evaluate whether a feature should be on or off.
+ /// A context that provides information to evaluate whether a feature should be on or off.
/// The cancellation token to cancel the operation.
/// True if the feature is enabled, otherwise false.
public async ValueTask IsEnabledAsync(string feature, TContext appContext, CancellationToken cancellationToken = default)
@@ -216,7 +216,7 @@ public async ValueTask GetVariantAsync(string feature, CancellationToke
throw new ArgumentNullException(nameof(feature));
}
- EvaluationEvent evaluationEvent = await EvaluateFeature(feature, context: null, useContext: false, cancellationToken);
+ EvaluationEvent evaluationEvent = await EvaluateFeature