diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 9a741300..5321fab2 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -7,7 +7,7 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTcxODU5OTU0IiwiZXhwIjoiMTU3MjQ -TODO: Seeder create widget is creating a new widgetbiz each loop iteration but create user is not, try both ways and performance test + TODO: License.cs using httpclient directly albeit trying to do it right` - Change to use httpclientfactory injected service: diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index d36b93de..0e68aba4 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -95,6 +95,10 @@ namespace AyaNova }); + //HTTP CLIENT FACTORY USED BY LICENSE.CS + //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1 + _newLog.LogDebug("BOOT: init HTTPClientFactory"); + services.AddHttpClient(); //2019-10-17 METRICS will not work just yet with .netcore 3.1 see here https://github.com/AppMetrics/AppMetrics/issues/480 @@ -450,7 +454,7 @@ namespace AyaNova { AyaNova.Core.License.FetchKeyAsync(apiServerState, dbContext, _newLog).Wait(); //NOTE: For unit testing make sure the time zone in util is set to the same figure as here to ensure list filter by date tests will work because server is on same page as user in terms of time - Util.Seeder.SeedDatabaseAsync(Util.Seeder.SeedLevel.MediumLocalServiceCompanyTrialDataSet, -7).Wait();//############################################################################################# + Util.Seeder.SeedDatabaseAsync(Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet, -7).Wait();//############################################################################################# } //TESTING #endif diff --git a/server/AyaNova/util/License.cs b/server/AyaNova/util/License.cs index f945a346..d55bd106 100644 --- a/server/AyaNova/util/License.cs +++ b/server/AyaNova/util/License.cs @@ -46,9 +46,8 @@ namespace AyaNova.Core //Trial key magic number for development and testing, all other guids will be fully licensed private static Guid TEST_TRIAL_KEY_DBID = new Guid("{A6D18A8A-5613-4979-99DA-80D07641A2FE}"); - //https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ - private static HttpClient _Client = new HttpClient(); + //Current license key, can be empty private static AyaNovaLicenseKey _ActiveLicense = new AyaNovaLicenseKey(); @@ -72,7 +71,7 @@ namespace AyaNova.Core internal class AyaNovaLicenseKey { public AyaNovaLicenseKey() - { + { Features = new List(); RegisteredTo = "UNLICENSED"; Id = RegisteredTo; @@ -358,7 +357,8 @@ namespace AyaNova.Core string sUrl = $"{LICENSE_SERVER_URL}rvr" + q.ToQueryString(); try { - var res = await _Client.GetStringAsync(sUrl); + //var res = await _Client.GetStringAsync(sUrl); + var res = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl); return res; } catch (Exception ex) @@ -391,7 +391,9 @@ namespace AyaNova.Core try { - string RawTextKeyFromRockfish = await _Client.GetStringAsync(sUrl); + + //string RawTextKeyFromRockfish = await _Client.GetStringAsync(sUrl); + string RawTextKeyFromRockfish = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl); //FUTURE: if there is any kind of error response or REASON or LicenseFetchStatus then here is //where to deal with it @@ -519,7 +521,7 @@ namespace AyaNova.Core } //Can't install a trial into a non-empty db - if (ParsedNewKey.TrialLicense && ! await DbUtil.DBIsEmptyAsync(ct, log)) + if (ParsedNewKey.TrialLicense && !await DbUtil.DBIsEmptyAsync(ct, log)) { throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first."); } diff --git a/server/AyaNova/util/ServiceProviderProvider.cs b/server/AyaNova/util/ServiceProviderProvider.cs index ba2d34f1..714dac0b 100644 --- a/server/AyaNova/util/ServiceProviderProvider.cs +++ b/server/AyaNova/util/ServiceProviderProvider.cs @@ -25,11 +25,12 @@ namespace AyaNova.Util { get { - #if (DEBUG) - if(_provider==null){ +#if (DEBUG) + if (_provider == null) + { throw new System.NotSupportedException("ServiceProviderProvider.cs - Attempt to use service provider before it's been initialized"); } - #endif +#endif return _provider; } set @@ -57,6 +58,14 @@ namespace AyaNova.Util } } + // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1 + internal static System.Net.Http.IHttpClientFactory HttpClientFactory + { + get + { + return Scope.ServiceProvider.GetRequiredService(); + } + } }