Skip to content

Commit

Permalink
fix: cannot add localized resource
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Mar 26, 2021
1 parent 327f10f commit fd5d9f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public static void ConfigureServices(IServiceCollection services, IConfiguration
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

services.AddScoped<ISharedStringLocalizerAsync, StringLocalizer>()
.AddTransient<IAdminStore<Entity.LocalizedResource>>(p =>
.AddTransient<IReadOnlyLocalizedResourceStore>(p =>
{
var factory = p.GetRequiredService<IHttpClientFactory>();
return new AdminStore<Entity.LocalizedResource>(Task.FromResult(factory.CreateClient("localizer")), p.GetRequiredService<ILogger<AdminStore<Entity.LocalizedResource>>>());
return new ReadOnlyLocalizedResourceStore(new AdminStore<Entity.LocalizedResource>(Task.FromResult(factory.CreateClient("localizer")), p.GetRequiredService<ILogger<AdminStore<Entity.LocalizedResource>>>()));
}).AddTransient<IReadOnlyCultureStore>(p =>
{
var factory = p.GetRequiredService<IHttpClientFactory>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Project: Aguafrommars/TheIdServer
// Copyright (c) 2021 @Olivier Lefebvre
using Aguacongas.IdentityServer.Store;
using Aguacongas.IdentityServer.Store.Entity;
using System.Threading;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.BlazorApp.Services
{
public interface IReadOnlyLocalizedResourceStore
{
Task<PageResponse<LocalizedResource>> GetAsync(PageRequest pageRequest, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Project: Aguafrommars/TheIdServer
// Copyright (c) 2021 @Olivier Lefebvre
using Aguacongas.IdentityServer.Store;
using Aguacongas.IdentityServer.Store.Entity;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Aguacongas.TheIdServer.BlazorApp.Services
{
public class ReadOnlyLocalizedResourceStore : IReadOnlyLocalizedResourceStore
{
private readonly IAdminStore<LocalizedResource> _adminStore;

public ReadOnlyLocalizedResourceStore(IAdminStore<LocalizedResource> adminStore)
{
_adminStore = adminStore ?? throw new ArgumentNullException(nameof(adminStore));
}

public Task<PageResponse<LocalizedResource>> GetAsync(PageRequest pageRequest, CancellationToken cancellationToken = default)
=> _adminStore.GetAsync(pageRequest, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Aguacongas.TheIdServer.BlazorApp.Infrastructure.Services
{
public class StringLocalizer : ISharedStringLocalizerAsync
{
private readonly IAdminStore<LocalizedResource> _store;
private readonly IReadOnlyLocalizedResourceStore _store;
private readonly IReadOnlyCultureStore _cultureStore;
private IEnumerable<LocalizedResource> _resources;
private IEnumerable<string> _cultureList;
Expand All @@ -28,7 +28,7 @@ public class StringLocalizer : ISharedStringLocalizerAsync

public event Action ResourceReady;

public StringLocalizer(IAdminStore<LocalizedResource> store,
public StringLocalizer(IReadOnlyLocalizedResourceStore store,
IReadOnlyCultureStore cultureStore,
ILogger<StringLocalizer> logger)
{
Expand Down Expand Up @@ -219,7 +219,7 @@ public void Dispose()
[SuppressMessage("Major Code Smell", "S2326:Unused type parameters should be removed", Justification = "Create an instance by T")]
public class SharedStringLocalizer<T> : StringLocalizer
{
public SharedStringLocalizer(IAdminStore<LocalizedResource> store,
public SharedStringLocalizer(IReadOnlyLocalizedResourceStore store,
IReadOnlyCultureStore cultureStore,
ILogger<SharedStringLocalizer<T>> logger)
: base(store, cultureStore, logger)
Expand Down

0 comments on commit fd5d9f5

Please sign in to comment.