Skip to content

Commit

Permalink
Fixed env logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Sep 28, 2024
1 parent 610588a commit 3c3c800
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Inc.TeamAssistant.Gateway/Apps/MainApp.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
};
Blazor.start({
environment: "@HostEnvironment.EnvironmentName"
webAssembly: {
environment: "@HostEnvironment.EnvironmentName"
}
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Inc.TeamAssistant.Gateway.Services.ServerCore;

internal sealed class ServerHostEnvironment : IWebAssemblyHostEnvironment
{
private readonly IWebHostEnvironment _hostEnvironment;
private readonly NavigationManager _navigationManager;

public ServerHostEnvironment(IWebHostEnvironment hostEnvironment, NavigationManager navigationManager)
{
_hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
_navigationManager = navigationManager ?? throw new ArgumentNullException(nameof(navigationManager));
}

public string Environment => _hostEnvironment.EnvironmentName;
public string BaseAddress => _navigationManager.BaseUri;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Inc.TeamAssistant.Primitives;
using Inc.TeamAssistant.Primitives.Languages;
using Inc.TeamAssistant.WebUI.Contracts;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Inc.TeamAssistant.Gateway.Services;

Expand All @@ -22,6 +24,9 @@ public static IServiceCollection AddServices(
ArgumentNullException.ThrowIfNull(authOptions);
ArgumentNullException.ThrowIfNull(openGraphOptions);
ArgumentException.ThrowIfNullOrWhiteSpace(webRootPath);

services
.TryAddScoped<IWebAssemblyHostEnvironment, ServerHostEnvironment>();

services
.AddSingleton(authOptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using Inc.TeamAssistant.Primitives.Languages;
using Inc.TeamAssistant.WebUI.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Inc.TeamAssistant.WebUI.Services.Clients;

internal sealed class ClientRenderContext : IRenderContext
{
private readonly NavigationManager _navigationManager;
private readonly IWebAssemblyHostEnvironment _hostEnvironment;

public ClientRenderContext(NavigationManager navigationManager)
public ClientRenderContext(NavigationManager navigationManager, IWebAssemblyHostEnvironment hostEnvironment)
{
_navigationManager = navigationManager ?? throw new ArgumentNullException(nameof(navigationManager));
_hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
}

public bool IsBrowser => true;

public bool IsDevelopment() => _navigationManager.BaseUri.StartsWith(
"http://localhost",
StringComparison.InvariantCultureIgnoreCase);
public bool IsDevelopment() => _hostEnvironment.IsDevelopment();

public (LanguageId CurrentLanguage, bool Selected) GetLanguageContext()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FluentValidation;
using Inc.TeamAssistant.WebUI.Contracts;
using Inc.TeamAssistant.WebUI.Features.Components;
using Inc.TeamAssistant.WebUI.Features.Constructor.Stages.Stage2;
using Inc.TeamAssistant.WebUI.Features.Constructor.Stages.Stage3;
using Inc.TeamAssistant.WebUI.Features.Notifications;
using Inc.TeamAssistant.WebUI.Routing;
Expand Down Expand Up @@ -34,7 +33,7 @@ internal static IServiceCollection AddServices(this IServiceCollection services)
.AddScoped(sp => ActivatorUtilities.CreateInstance<AppLocalStorage>(sp, appVersion))
.AddScoped<IValidator<BotDetailsItemFormModel>, BotDetailsItemFormModelValidator>()
.AddSingleton<IRenderContext, ClientRenderContext>()
.AddSingleton<IMessageProvider, MessageProviderClient>()
.AddScoped<IMessageProvider, MessageProviderClient>()
.AddSingleton<EventsProvider>()
.AddNotificationsService(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(5));

Expand Down

0 comments on commit 3c3c800

Please sign in to comment.