Skip to content
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

Support for trimming & AOT #94

Merged
merged 15 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

# Make sure unix eol in shell scripts
*.sh eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,4 @@ coverage.xml
/format-report.json
src/.idea
/samples/ASP.NETCore/WebApplication/wwwroot/lib/
/samples/BlazorWasm/wwwroot/lib/
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
- .NET Framework 4.5+
- Other runtimes which implement .NET Standard 2.0+ like .NET Core 2.0+, Xamarin.Android 8.0+, Xamarin.iOS 10.14+, etc. (For more details, please refer to [this table](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0).)

https://configcat.com
Starting with v9.3.0, the ConfigCat SDK can be used in applications that employ [trimmed self-contained](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) or various ahead-of-time (AOT) compilation deployment models.
The SDK has been tested with the following AOT solutions:
* [Native AOT](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/) - see also [Sample .NET Console app](https://github.com/configcat/.net-sdk/tree/master/samples/ConsoleApp)
* [Mono AOT](https://www.mono-project.com/docs/advanced/aot/) - see also [Sample .NET MAUI app](https://github.com/configcat/.net-sdk/tree/master/samples/MAUI)
* [Mono AOT for WebAssembly/Emscripten (wasm-tools)](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-build-tools-and-aot) - see also [Sample ASP.NET Core Blazor WebAssembly app](https://github.com/configcat/.net-sdk/tree/master/samples/BlazorWasm)
* [IL2CPP](https://docs.unity3d.com/2021.3/Documentation/Manual/IL2CPP.html) - see also [Sample Unity WebGL scripts](https://github.com/configcat/.net-sdk/tree/master/samples/UnityWebGL)
* [.NET Native](https://learn.microsoft.com/en-us/windows/uwp/dotnet-native/) (UWP)
* [Crossgen2](https://devblogs.microsoft.com/dotnet/conversation-about-crossgen2/) (ReadyToRun)
* [Ngen](https://learn.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator) (Native Image Generator)

ConfigCat SDK for .NET provides easy integration for your application to ConfigCat.

Expand Down Expand Up @@ -48,7 +56,7 @@ var client = ConfigCatClient.Get("#YOUR-SDK-KEY#");

### 5. Get your setting value:
```c#
var isMyAwesomeFeatureEnabled = client.GetValue("isMyAwesomeFeatureEnabled", false);
var isMyAwesomeFeatureEnabled = await client.GetValueAsync("isMyAwesomeFeatureEnabled", false);

if(isMyAwesomeFeatureEnabled)
{
Expand All @@ -74,16 +82,18 @@ Read more about [Targeting here](https://configcat.com/docs/advanced/targeting).
```c#
User currentUser = new User("435170f4-8a8b-4b67-a723-505ac7cdea92");

var isMyAwesomeFeatureEnabled = client.GetValue(
var isMyAwesomeFeatureEnabled = await client.GetValueAsync(
"isMyAwesomeFeatureEnabled",
defaultValue: false,
user: currentUser);
```

## Sample/Demo apps
* [Sample Console App](https://github.com/configcat/.net-sdk/tree/master/samples/ConsoleApp)
* [Sample Web App](https://github.com/configcat/.net-sdk/tree/master/samples/ASP.NETCore)

* [Sample Multi Page Web App](https://github.com/configcat/.net-sdk/tree/master/samples/ASP.NETCore)
* [Sample Single Page Web App](https://github.com/configcat/.net-sdk/tree/master/samples/BlazorWasm)
* [Sample Mobile/Windows Store App](https://github.com/configcat/.net-sdk/tree/master/samples/MAUI)

## Polling Modes
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://configcat.com/docs/sdk-reference/dotnet/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/NewVersionLib/NewVersionLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<AssemblyName>ConfigCatClientBenchmarks</AssemblyName>
<RootNamespace>ConfigCat.Client.Benchmarks.New</RootNamespace>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/OldVersionLib/OldVersionLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
to which the interals are made visible by ConfigCat.Client. -->
<AssemblyName>ConfigCatClientTests</AssemblyName>
<RootNamespace>ConfigCat.Client.Benchmarks.New</RootNamespace>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
Expand Down
2 changes: 1 addition & 1 deletion samples/ASP.NETCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a simple .NET Core web application to demonstrate how to use the ConfigCat SDK.

1. Install [.NET Core](https://dotnet.microsoft.com/download)
1. Install the [.NET SDK](https://dotnet.microsoft.com/download)
2. Change dir to `/WebApplication`
```bash
cd WebApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace WebApplication.Adapters;
namespace ConfigCat.Client.Extensions.Adapters;

public class ConfigCatToMSLoggerAdapter : ConfigCat.Client.IConfigCatLogger
{
Expand Down
7 changes: 3 additions & 4 deletions samples/ASP.NETCore/WebApplication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System;
using ConfigCat.Client;
using ConfigCat.Client.Extensions.Adapters;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using WebApplication.Adapters;

var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);

Expand All @@ -22,7 +21,7 @@
{
var logger = sp.GetRequiredService<Microsoft.Extensions.Logging.ILogger<ConfigCatClient>>();

return ConfigCatClient.Get(configCatSdkKey, options =>
return ConfigCatClient.Get(configCatSdkKey!, options =>
{
options.PollingMode = PollingModes.LazyLoad(cacheTimeToLive: TimeSpan.FromSeconds(120));
options.Logger = new ConfigCatToMSLoggerAdapter(logger);
Expand Down
8 changes: 4 additions & 4 deletions samples/ASP.NETCore/WebApplication/WebApplication.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\ConfigCatClient\ConfigCatClient.csproj" />
<!-- Use PackageReference instead of the ProjectReference above in your application. -->
<!--<PackageReference Include="ConfigCat.Client" Version="9.0.0" />-->
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.*" />
<!--<PackageReference Include="ConfigCat.Client" Version="9.*" />-->
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.*" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions samples/BlazorWasm/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
27 changes: 27 additions & 0 deletions samples/BlazorWasm/BlazorWasm.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RunAOTCompilation>true</RunAOTCompilation>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\ConfigCatClient\ConfigCatClient.csproj" />
<!-- Use PackageReference instead of the ProjectReference above in your application. -->
<!--<PackageReference Include="ConfigCat.Client" Version="9.*" />-->
</ItemGroup>

<ItemGroup>
<Compile Include="..\ASP.NETCore\WebApplication\Adapters\ConfigCatToMSLoggerAdapter.cs" Link="Adapters\ConfigCatToMSLoggerAdapter.cs" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions samples/BlazorWasm/BlazorWasm.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProjectReferences", "ProjectReferences", "{73A8C054-9067-4474-B6D0-A0A924DF5DB6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfigCatClient", "..\..\src\ConfigCatClient\ConfigCatClient.csproj", "{8F64DC62-D524-4310-A620-03D65ED829BC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWasm", "BlazorWasm.csproj", "{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Benchmark|Any CPU = Benchmark|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8F64DC62-D524-4310-A620-03D65ED829BC}.Benchmark|Any CPU.ActiveCfg = Benchmark|Any CPU
{8F64DC62-D524-4310-A620-03D65ED829BC}.Benchmark|Any CPU.Build.0 = Benchmark|Any CPU
{8F64DC62-D524-4310-A620-03D65ED829BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F64DC62-D524-4310-A620-03D65ED829BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F64DC62-D524-4310-A620-03D65ED829BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F64DC62-D524-4310-A620-03D65ED829BC}.Release|Any CPU.Build.0 = Release|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Benchmark|Any CPU.ActiveCfg = Release|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Benchmark|Any CPU.Build.0 = Release|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0E7F85F-048E-48A5-91BA-BB73FF3D7118}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8F64DC62-D524-4310-A620-03D65ED829BC} = {73A8C054-9067-4474-B6D0-A0A924DF5DB6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F653DA7-4E85-40D3-AB27-E2599966E0AC}
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions samples/BlazorWasm/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>
77 changes: 77 additions & 0 deletions samples/BlazorWasm/Layout/MainLayout.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}

.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}

.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}

.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}

.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
29 changes: 29 additions & 0 deletions samples/BlazorWasm/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">BlazorWasm</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>

<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>
</nav>
</div>

@code {
private bool collapseNavMenu = true;

private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
Loading
Loading