Skip to content

Commit

Permalink
fix: remove dependency on NewtonSoft.Json (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyangers authored Jan 23, 2022
1 parent cb4c9f4 commit f83f0b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
48 changes: 24 additions & 24 deletions src/Finbuckle.MultiTenant/Finbuckle.MultiTenant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<Choose>
<When Condition=" '$(TargetFramework)' == 'net6.0' ">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.*-*"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.*-*" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.*-*" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'net5.0' ">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.*"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.*"/>
</ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.*" />
</ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.*"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.*" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.*" />
<PackageReference Include="System.Text.Json" Version="6.0.*-*" />
</ItemGroup>
</When>
</Choose>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright Finbuckle LLC, Andrew White, and Contributors.
// Refer to the solution LICENSE file for more inforation.

using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Newtonsoft.Json;

namespace Finbuckle.MultiTenant.Stores
{
Expand All @@ -25,7 +25,8 @@ public DistributedCacheStore(IDistributedCache cache, string keyPrefix, TimeSpan
public async Task<bool> TryAddAsync(TTenantInfo tenantInfo)
{
var options = new DistributedCacheEntryOptions { SlidingExpiration = slidingExpiration };
var bytes = JsonConvert.SerializeObject(tenantInfo);
var bytes = JsonSerializer.Serialize(tenantInfo);

await cache.SetStringAsync($"{keyPrefix}id__{tenantInfo.Id}", bytes, options);
await cache.SetStringAsync($"{keyPrefix}identifier__{tenantInfo.Identifier}", bytes, options);

Expand All @@ -38,7 +39,7 @@ public async Task<bool> TryAddAsync(TTenantInfo tenantInfo)
if (bytes == null)
return null;

var result = JsonConvert.DeserializeObject<TTenantInfo>(bytes);
var result = JsonSerializer.Deserialize<TTenantInfo>(bytes);

// Refresh the identifier version to keep things synced
await cache.RefreshAsync($"{keyPrefix}identifier__{result.Identifier}");
Expand All @@ -57,7 +58,7 @@ public Task<IEnumerable<TTenantInfo>> GetAllAsync()
if (bytes == null)
return null;

var result = JsonConvert.DeserializeObject<TTenantInfo>(bytes);
var result = JsonSerializer.Deserialize<TTenantInfo>(bytes);

// Refresh the identifier version to keep things synced
await cache.RefreshAsync($"{keyPrefix}id__{result.Id}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Finbuckle.MultiTenant.Stores
{
Expand All @@ -27,7 +27,7 @@ public HttpRemoteStoreClient(IHttpClientFactory clientFactory)
return null;

var json = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<TTenantInfo>(json);
var result = JsonSerializer.Deserialize<TTenantInfo>(json);

return result;
}
Expand Down

0 comments on commit f83f0b1

Please sign in to comment.