Skip to content

Commit 116ee29

Browse files
committed
Use Unlaunch feature flag
1 parent ce20b08 commit 116ee29

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/Infrastructure/Infrastructure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
1414
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
15+
<PackageReference Include="unlaunch" Version="1.0.0" />
1516
</ItemGroup>
1617
<ItemGroup>
1718
<ProjectReference Include="..\ApplicationCore\ApplicationCore.csproj" />

src/Web/Pages/Index.cshtml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@page
2+
@using Microsoft.eShopWeb.Web.Services;
3+
@inject UnlaunchService UnlaunchService;
24
@{
35
ViewData["Title"] = "Catalog";
46
@model IndexModel
@@ -27,11 +29,18 @@
2729
<partial name="_pagination" for="CatalogModel.PaginationInfo" />
2830

2931
<div class="esh-catalog-items row">
30-
@foreach (var catalogItem in Model.CatalogModel.CatalogItems)
31-
{
32-
<div class="esh-catalog-item col-md-4">
33-
<partial name="_product" for="@catalogItem" />
34-
</div>
32+
@{
33+
if (UnlaunchService.IsEnabled(HttpContext.Connection.RemoteIpAddress.ToString()))
34+
{
35+
Model.CatalogModel.CatalogItems.Reverse();
36+
}
37+
38+
foreach (var catalogItem in Model.CatalogModel.CatalogItems)
39+
{
40+
<div class="esh-catalog-item col-md-4">
41+
<partial name="_product" for="@catalogItem" />
42+
</div>
43+
}
3544
}
3645
</div>
3746
<partial name="_pagination" for="CatalogModel.PaginationInfo" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using io.unlaunch;
2+
3+
namespace Microsoft.eShopWeb.Web.Services
4+
{
5+
public class UnlaunchService
6+
{
7+
private const string FlagKey = "catalog_reverse";
8+
9+
private readonly IUnlaunchClient _client;
10+
11+
public UnlaunchService(IUnlaunchClient client)
12+
{
13+
_client = client;
14+
}
15+
16+
public bool IsEnabled(string userIdentity)
17+
{
18+
var variation = _client.GetVariation(FlagKey, userIdentity);
19+
return variation == "on";
20+
}
21+
}
22+
}

src/Web/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using BlazorAdmin.Services;
44
using Blazored.LocalStorage;
55
using BlazorShared;
6+
using io.unlaunch;
67
using Microsoft.AspNetCore.Authentication.Cookies;
78
using Microsoft.AspNetCore.Builder;
89
using Microsoft.AspNetCore.DataProtection;
@@ -16,6 +17,7 @@
1617
using Microsoft.eShopWeb.Infrastructure.Data;
1718
using Microsoft.eShopWeb.Infrastructure.Identity;
1819
using Microsoft.eShopWeb.Web.Configuration;
20+
using Microsoft.eShopWeb.Web.Services;
1921
using Microsoft.Extensions.Configuration;
2022
using Microsoft.Extensions.DependencyInjection;
2123
using Microsoft.Extensions.Diagnostics.HealthChecks;
@@ -161,6 +163,9 @@ public void ConfigureServices(IServiceCollection services)
161163
services.AddScoped<HttpService>();
162164
services.AddBlazorServices();
163165

166+
services.AddSingleton<IUnlaunchClient>(UnlaunchClient.Create("prod-server-0bdc1324-cbec-4740-83e9-86045d1cd93f"));
167+
services.AddTransient<UnlaunchService>();
168+
164169
services.AddDatabaseDeveloperPageExceptionFilter();
165170

166171
_services = services; // used to debug registered services

0 commit comments

Comments
 (0)