diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs
index 5988dc4..e0bb3ce 100644
--- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs
+++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs
@@ -1,5 +1,4 @@
using EasyMicroservices.Cores.AspCoreApi.Interfaces;
-using EasyMicroservices.Cores.Database.Interfaces;
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.ServiceContracts;
using EasyMicroservices.Utilities.Collections.Generic;
@@ -46,15 +45,7 @@ public AspCoreAuthorization(IBaseUnitOfWork baseUnitOfWork)
///
public async Task CheckIsAuthorized(HttpContext httpContext)
{
- try
- {
- var result = await httpContext.AuthenticateAsync("Bearer");
- await httpContext.SignInAsync("Bearer", result.Principal);
- }
- catch (Exception exxx)
- {
- var qq = exxx;
- }
+ await httpContext.AuthenticateAsync("Bearer");
var hasPermission = await HasPermission(httpContext);
if (!hasPermission.IsSuccess)
return hasPermission.ToContract();
@@ -72,7 +63,8 @@ async Task GetMicroserviceName()
static readonly ConcurrentTreeDictionary TreeDictionary = new ConcurrentTreeDictionary();
async Task FetchData(string roleName)
{
- var servicePermissionClient = new Authentications.GeneratedServices.ServicePermissionClient(AuthenticationRouteAddress, new System.Net.Http.HttpClient());
+ var httpClient = new System.Net.Http.HttpClient();
+ var servicePermissionClient = new Authentications.GeneratedServices.ServicePermissionClient(AuthenticationRouteAddress, httpClient);
var permissionsResult = await servicePermissionClient.GetAllPermissionsByAsync(new Authentications.GeneratedServices.ServicePermissionRequestContract()
{
MicroserviceName = await GetMicroserviceName(),
diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj
index 42731bb..857e710 100644
--- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj
@@ -4,7 +4,7 @@
net6.0;net7.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
asp core servces.
EasyMicroservices@gmail.com
core,cores,base,database,services,asp,aspnet
diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj
index fa95a40..1f440ee 100644
--- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj
@@ -4,7 +4,7 @@
net6.0;net7.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
asp core servces.
EasyMicroservices@gmail.com
core,cores,base,database,services,asp,aspnet,aspcore,efcore
@@ -22,7 +22,6 @@
-
diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs
index b19a82e..a476380 100644
--- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs
+++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs
@@ -1,7 +1,9 @@
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi;
using EasyMicroservices.Cores.Database.Managers;
using EasyMicroservices.Cores.Models;
+using EasyMicroservices.Database.Interfaces;
using EasyMicroservices.ServiceContracts;
+using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
@@ -31,10 +33,6 @@ public WhiteLabelManager(IServiceProvider serviceProvider)
///
///
///
- public HttpClient HttpClient { get; set; } = new HttpClient();
- ///
- ///
- ///
public bool IsInitialized { get; set; }
WhiteLabelInfo _CurrentWhiteLabel;
@@ -69,11 +67,12 @@ string GetDefaultUniqueIdentity(ICollection whiteLables, lon
///
///
///
+ ///
///
///
///
///
- public async Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes)
+ public async Task Initialize(IHttpContextAccessor httpContext, string microserviceName, string whiteLableRoute, params Type[] dbContextTypes)
{
try
{
@@ -85,11 +84,16 @@ public async Task Initialize(string microserviceName, string whi
Console.WriteLine($"WhiteLabelManager Initialize! {microserviceName} {whiteLableRoute}");
if (dbContextTypes.IsEmpty())
return CurrentWhiteLabel;
- var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(whiteLableRoute, HttpClient);
+ HttpClient httpClient = new HttpClient();
+ if (httpContext?.HttpContext != null && httpContext.HttpContext.Request.Headers.TryGetValue("Authorization", out var authorizationHeader))
+ {
+ httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authorizationHeader.ToString().Replace("Bearer ", ""));
+ }
+ var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(whiteLableRoute, httpClient);
var whiteLabels = await whiteLabelClient.GetAllAsync().AsCheckedResult(x => x.Result).ConfigureAwait(false);
var defaultUniqueIdentity = GetDefaultUniqueIdentity(whiteLabels, null);
- var microserviceClient = new WhiteLables.GeneratedServices.MicroserviceClient(whiteLableRoute, HttpClient);
+ var microserviceClient = new WhiteLables.GeneratedServices.MicroserviceClient(whiteLableRoute, httpClient);
var microservices = await microserviceClient.GetAllAsync().ConfigureAwait(false);
var foundMicroservice = microservices.Result.FirstOrDefault(x => x.Name.Equals(microserviceName, StringComparison.OrdinalIgnoreCase));
if (foundMicroservice == null)
@@ -113,7 +117,7 @@ public async Task Initialize(string microserviceName, string whi
var uniqueIdentityManager = new UnitOfWork(_serviceProvider).GetUniqueIdentityManager() as DefaultUniqueIdentityManager;
- var microserviceContextTableClient = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(whiteLableRoute, HttpClient);
+ var microserviceContextTableClient = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(whiteLableRoute, httpClient);
var microserviceContextTables = await microserviceContextTableClient.GetAllAsync().ConfigureAwait(false);
HashSet addedInWhitLabels = new HashSet();
@@ -125,7 +129,7 @@ public async Task Initialize(string microserviceName, string whi
foreach (var contextType in dbContextTypes)
{
- var contextTableClient = new WhiteLables.GeneratedServices.ContextTableClient(whiteLableRoute, HttpClient);
+ var contextTableClient = new WhiteLables.GeneratedServices.ContextTableClient(whiteLableRoute, httpClient);
var contextTables = await contextTableClient.GetAllAsync().ConfigureAwait(false);
using var instanceOfContext = _serviceProvider.GetService(contextType) as DbContext;
string contextName = uniqueIdentityManager.GetContextName(contextType);
diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs
index cbbd91f..619cc30 100644
--- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs
+++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs
@@ -12,6 +12,7 @@
using EasyMicroservices.Mapper.Interfaces;
using EasyMicroservices.Mapper.SerializerMapper.Providers;
using EasyMicroservices.Serialization.Newtonsoft.Json.Providers;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization;
using System;
@@ -366,7 +367,7 @@ public virtual Task InitializeWhiteLabel(string microserviceName, string whiteLa
{
var whiteLabelManager = serviceProvider.GetService();
if (!whiteLabelManager.IsInitialized)
- return await whiteLabelManager.Initialize(microserviceName, whiteLableRoute, dbContextTypes);
+ return await whiteLabelManager.Initialize(serviceProvider.GetService(), microserviceName, whiteLableRoute, dbContextTypes);
return whiteLabelManager.CurrentWhiteLabel;
};
return Task.CompletedTask;
diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj
index 601d933..fad3bb3 100644
--- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj
@@ -4,7 +4,7 @@
netstandard2.0;netstandard2.1;net6.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
core of database.
EasyMicroservices@gmail.com
core,cores,base,client,clients
diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj
index 375de15..4ddb602 100644
--- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj
@@ -4,7 +4,7 @@
netstandard2.0;netstandard2.1;net45;net6.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
core contracts.
EasyMicroservices@gmail.com
core,cores,base,contract,contracts,dto,dtos
diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj
index 426e056..60d2c4f 100644
--- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj
@@ -4,7 +4,7 @@
netstandard2.0;netstandard2.1;net45;net6.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
core of database.
EasyMicroservices@gmail.com
core,cores,base,database
diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj
index c9dc1e9..6cf6434 100644
--- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj
@@ -4,7 +4,7 @@
net6.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
ef core of database.
EasyMicroservices@gmail.com
core,cores,base,database,ef,efcore
diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj
index 333b9c7..b53d3d0 100644
--- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj
+++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj
@@ -4,7 +4,7 @@
net6.0;net8.0
AnyCPU;x64;x86
EasyMicroservices
- 0.0.0.56
+ 0.0.0.57
ef core of Relational database.
EasyMicroservices@gmail.com
core,cores,base,database,ef,efcore,Relational
diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs
index 588bf58..00744f5 100644
--- a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs
+++ b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs
@@ -35,6 +35,7 @@ public async Task InitializeAsync()
});
StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:6041");
serviceCollection.AddTransient();
+ serviceCollection.AddHttpContextAccessor();
ServiceProvider = serviceCollection.BuildServiceProvider();
using (var scope = ServiceProvider.CreateAsyncScope())
{