Initial commit - MassTech UI
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace UI.Config.PostBuild
|
||||
{
|
||||
public static class CultureRetrieval
|
||||
{
|
||||
public static async Task RetriveCulture(this IServiceProvider services)
|
||||
{
|
||||
|
||||
|
||||
var js = services.GetRequiredService<IJSRuntime>();
|
||||
var cultureName = await js.InvokeAsync<string>("cultureInfo.get") ?? "en";
|
||||
|
||||
if (cultureName.Contains("|"))
|
||||
{
|
||||
var cultureParts = cultureName.Split('|');
|
||||
var cPart = cultureParts.FirstOrDefault(p => p.StartsWith("c="));
|
||||
if (cPart != null)
|
||||
{
|
||||
cultureName = cPart.Substring(2);
|
||||
}
|
||||
}
|
||||
|
||||
var culture = new CultureInfo(cultureName);
|
||||
CultureInfo.DefaultThreadCurrentCulture = culture;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using MudBlazor.Extensions;
|
||||
using SoloX.BlazorJsonLocalization;
|
||||
|
||||
namespace UI.Config.PostBuild
|
||||
{
|
||||
public static class LocalizationStart
|
||||
{
|
||||
public static async Task LoadTranslations(this IServiceProvider services)
|
||||
{
|
||||
var authLocalizer = services.GetRequiredService<IStringLocalizer<Auth.RCL.SharedRes>>();
|
||||
var layoutLocalizer = services.GetRequiredService<IStringLocalizer<LayoutLib.RCL.SharedRes>>();
|
||||
var ecommerceLocalizer = services.GetRequiredService<IStringLocalizer<ECommerce.RCL.SharedRes>>();
|
||||
|
||||
await Task.WhenAll(
|
||||
authLocalizer.LoadAsync().AsTask(),
|
||||
layoutLocalizer.LoadAsync().AsTask(),
|
||||
ecommerceLocalizer.LoadAsync().AsTask()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.JSInterop;
|
||||
using SoloX.BlazorJsonLocalization;
|
||||
|
||||
namespace UI.Config.Register
|
||||
{
|
||||
public class LocalizationHttpClient : HttpClient { }
|
||||
|
||||
public static class LocalizationSetup
|
||||
{
|
||||
public static IServiceCollection RegLocalization(
|
||||
this IServiceCollection services,
|
||||
string address
|
||||
)
|
||||
{
|
||||
services.AddHttpClient<LocalizationHttpClient>(sp =>
|
||||
{
|
||||
sp.BaseAddress = new Uri(address);
|
||||
});
|
||||
services.AddJsonLocalization(builder =>
|
||||
{
|
||||
builder
|
||||
.UseHttpClientJson(options =>
|
||||
{
|
||||
|
||||
options.ResourcesPath = "resources";
|
||||
options.Assemblies = [typeof(LayoutLib.RCL.SharedRes).Assembly, typeof(Auth.RCL.SharedRes).Assembly, typeof(ECommerce.RCL.SharedRes).Assembly];
|
||||
options.HttpClientBuilder = sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(LocalizationHttpClient));
|
||||
|
||||
});
|
||||
}, ServiceLifetime.Singleton);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
// using AuthModule;
|
||||
// using AuthModule.Services;
|
||||
using ECommerceModule.Config;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Http;
|
||||
|
||||
namespace UI.Config.Register;
|
||||
|
||||
public static class RegisteringServices
|
||||
{
|
||||
public static IServiceCollection RegisterServices(
|
||||
this IServiceCollection services,
|
||||
IConfiguration config
|
||||
)
|
||||
{
|
||||
services.AddHTTPClients(config);
|
||||
services.RegisteredServices();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection RegisteredServices(this IServiceCollection services)
|
||||
{
|
||||
// services.AuthModuleServices();
|
||||
services.ECommerceModuleServices();
|
||||
|
||||
// Common Services
|
||||
services.AddScoped<Common.Services.IToastService, Common.Services.ToastService>();
|
||||
|
||||
// Commerce Module Services
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddHTTPClients(
|
||||
this IServiceCollection services,
|
||||
IConfiguration config
|
||||
)
|
||||
{
|
||||
services.AddHttpClient(
|
||||
"Auth",
|
||||
client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:2002/api/v1/");
|
||||
}
|
||||
);
|
||||
services.AddHttpClient(
|
||||
"Commerce",
|
||||
client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:2001/api/v1/");
|
||||
}
|
||||
);
|
||||
services.AddHttpClient(
|
||||
"CDN",
|
||||
client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:2003/api/v1/");
|
||||
}
|
||||
);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user