From af7f74c563a860b3bd1e3c5ada48ff2f233cb6b6 Mon Sep 17 00:00:00 2001 From: arsalan falahpour Date: Fri, 9 Jul 2021 14:01:00 +0430 Subject: [PATCH 1/5] Stable 2.0.6 from 2.0.1 --- src/Directory.Build.props | 6 +-- .../DefaultDesignTimeDbContextFactoryBase.cs | 14 +++++-- .../ApplicationStartup/BaseAppStartup.cs | 18 ++++----- .../Source/ApplicationStartup/IAppStartup.cs | 6 +-- .../AllDotNetCenterDIC.cs | 2 - .../DependencyContainers/AspNetCoreDIC.cs | 4 +- .../DependencyContainers/AutoMapperDIC.cs | 2 +- .../DependencyContainers/HttpContextDIC.cs | 2 +- .../DependencyContainers/LoggerProviderDIC.cs | 26 +++++++++++++ .../DependencyContainers/MediatRDIC.cs | 1 - .../PreConfigurationDIC.cs | 18 +++++++++ .../DependencyContainers/WebHostingDIC.cs | 12 +++++- .../SupportAllDotNetCenterServices.cs | 2 +- .../Interfaces/SupportAutoMapper.cs | 2 +- .../Interfaces/SupportConfiguration.cs | 2 +- .../Interfaces/SupportDateTime.cs | 2 +- .../Interfaces/SupportHttpContextServices.cs | 2 +- .../Interfaces/SupportLoggerProviders.cs | 8 ++++ .../Interfaces/SupportLoggingServices.cs | 13 +------ .../Interfaces/SupportMediateR.cs | 2 +- .../Interfaces/SupportPreConfiguration.cs | 10 +++++ .../Interfaces/SupportWebHosting.cs | 2 +- .../Services/AllDotNetCenterServices.cs | 2 +- .../Services/AutoMapperService.cs | 2 +- .../Services/ConfigurationService.cs | 2 +- .../Services/DateTimeService.cs | 2 +- .../Services/HttpContextServices.cs | 9 +---- .../Services/LoggerProviderService.cs | 25 +++++++++++++ .../Services/LoggingService.cs | 3 +- .../Services/MediateRService.cs | 2 +- .../Services/PreConfigurationService.cs | 37 +++++++++++++++++++ .../Services/WebHostingService.cs | 2 +- .../Services/WebHostingServiceWrapper.cs | 1 - .../CommonServiceCollectionExtension.cs | 2 +- .../Hosting/CommonWebHostBuilderExtension.cs | 20 +++++++--- .../Kestrel/DefaultKestrelExtension.cs | 6 +-- .../DefaultRazorpagesMiddlewareExtension.cs | 7 ++-- .../Source/Middlewares/ExceptionMiddleware.cs | 2 +- .../Source/Middlewares/StopWatchMiddleware.cs | 7 ++-- .../Common/Managers/SignInManagerService.cs | 3 -- .../Common/Managers/UserManagerService.cs | 3 +- .../ManagerServicesDIC.cs | 11 +++--- .../BaseIdentityDbContext.cs | 14 +++++-- .../Services/Source/BaseCurrentUserService.cs | 11 +++++- .../Services/Source/BaseIdentityService.cs | 1 - .../Source/Managers/BaseAppSignInManager.cs | 19 +++++++--- .../Source/Managers/BaseAppUserManager.cs | 23 ++++++++---- ...tingIdentityAuthenticationStateProvider.cs | 8 +++- .../Source/UserAuthenticationService.cs | 1 + .../RazorPages/Source/Pages/BasePageModel.cs | 2 +- .../RazorPages/Source/Pages/BaseRazorPage.cs | 2 +- .../Mvc/Source/Controllers/BaseController.cs | 2 +- .../ConfigurationManagerDIC.cs | 12 ++++++ .../ConfigurationsCoreDIC.cs | 4 ++ .../Interfaces/ConfigurationServices.cs | 2 +- .../Core/Source/Services/BaseConfigService.cs | 3 +- .../Services/ConfigurationManagerService.cs | 4 +- .../ConfigurationServiceCollectionServices.cs | 6 +++ 58 files changed, 298 insertions(+), 120 deletions(-) create mode 100644 src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/LoggerProviderDIC.cs create mode 100644 src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/PreConfigurationDIC.cs create mode 100644 src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggerProviders.cs create mode 100644 src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportPreConfiguration.cs create mode 100644 src/Web/Core/Source/Common/DIContainerServices/Services/LoggerProviderService.cs create mode 100644 src/Web/Core/Source/Common/DIContainerServices/Services/PreConfigurationService.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 045d954..a470a13 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -18,9 +18,9 @@ latest https://github.com/arsalanfallahpour/DotNetCenter.Beyond.git - 0.1.15 - 0.1.15 - 0.1.15 + 0.2.5 + 0.2.5 + 0.2.5 3.3.2 3.9.0-2.final diff --git a/src/ObjRelMapping/Core/Source/DbContext/DesignTime/DefaultDesignTimeDbContextFactoryBase.cs b/src/ObjRelMapping/Core/Source/DbContext/DesignTime/DefaultDesignTimeDbContextFactoryBase.cs index ace11a2..71d082b 100644 --- a/src/ObjRelMapping/Core/Source/DbContext/DesignTime/DefaultDesignTimeDbContextFactoryBase.cs +++ b/src/ObjRelMapping/Core/Source/DbContext/DesignTime/DefaultDesignTimeDbContextFactoryBase.cs @@ -17,9 +17,17 @@ public override TContext CreateDbContext(string[] args) .AddJsonFile($"appsettings.{applicationEnvironment}.json", true) .AddEnvironmentVariables() .Build(); - var path = args[1]; - basePath = path; - Console.WriteLine($"base path : {basePath}"); + if (args.Length == 1) + { + basePath = args[0] + $"{separator}"; + Console.WriteLine($"base path : {basePath}"); + } + if (args.Length == 2) + { + basePath = args[1] + $"{separator}"; + Console.WriteLine($"base path : {basePath}"); + } + return Create(configuration); } } diff --git a/src/Web/Core/Source/ApplicationStartup/BaseAppStartup.cs b/src/Web/Core/Source/ApplicationStartup/BaseAppStartup.cs index e456ec4..43ff722 100644 --- a/src/Web/Core/Source/ApplicationStartup/BaseAppStartup.cs +++ b/src/Web/Core/Source/ApplicationStartup/BaseAppStartup.cs @@ -1,4 +1,4 @@ -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; +using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -10,17 +10,13 @@ namespace DotNetCenter.Beyond.Web.Core.Common { - public abstract class BaseAppStartup : IAppStartup + public abstract class BaseAppStartup : IAppStartup { - public BaseAppStartup(SupportConfiguration configuration, SupportWebHosting webHosting, ILoggerFactory logger) - { - Configuration = configuration; - WebHosting = webHosting; - LoggerFactory = logger; - } - public SupportConfiguration Configuration { get; } - public SupportWebHosting WebHosting { get; } - public ILoggerFactory LoggerFactory { get; } + public BaseAppStartup(SupportPreConfiguration providedServices) + => _preProvidedServices = providedServices; + + public SupportPreConfiguration PreProvidedServices => _preProvidedServices; + private readonly SupportPreConfiguration _preProvidedServices; public abstract void ConfigureServices(IServiceCollection services); public abstract void Configure(IApplicationBuilder app); } diff --git a/src/Web/Core/Source/ApplicationStartup/IAppStartup.cs b/src/Web/Core/Source/ApplicationStartup/IAppStartup.cs index 61a9a1d..70d2da7 100644 --- a/src/Web/Core/Source/ApplicationStartup/IAppStartup.cs +++ b/src/Web/Core/Source/ApplicationStartup/IAppStartup.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Common { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -11,9 +11,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - public interface IAppStartup + public interface IAppStartup { - TConfiguration Configuration { get; } + SupportPreConfiguration PreProvidedServices { get; } void ConfigureServices(IServiceCollection services); void Configure(IApplicationBuilder app); } diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AllDotNetCenterDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AllDotNetCenterDIC.cs index 621a4f7..46f8ff9 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AllDotNetCenterDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AllDotNetCenterDIC.cs @@ -1,7 +1,5 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AspNetCoreDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AspNetCoreDIC.cs index be943a0..065bf92 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AspNetCoreDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AspNetCoreDIC.cs @@ -1,6 +1,5 @@  namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using DotNetCenter.Beyond.Web.Core.Controllers; using Microsoft.Extensions.DependencyInjection; @@ -14,10 +13,9 @@ public class AspNetCoreDIC { public void AddAspNetCoreService(ref IServiceCollection services) { - services.AddWebHostingService(); services.AddTransient(); - services.AddSingleton(); services.AddTransient(typeof(SupportLoggingServices<>), typeof(LoggingService<>)); + services.TryAddLoggerProviderServices(); } } } diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AutoMapperDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AutoMapperDIC.cs index 547fbe0..4849792 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AutoMapperDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/AutoMapperDIC.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/HttpContextDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/HttpContextDIC.cs index 8659df7..2650cdf 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/HttpContextDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/HttpContextDIC.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/LoggerProviderDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/LoggerProviderDIC.cs new file mode 100644 index 0000000..a851246 --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/LoggerProviderDIC.cs @@ -0,0 +1,26 @@ +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers +{ + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; + using Microsoft.AspNetCore.Hosting; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + public static class LoggerProviderDIC + { + public static IServiceCollection AddLoggerProviderServices(this IServiceCollection services) + { + services.AddSingleton(); + return services; + } + + public static IServiceCollection TryAddLoggerProviderServices(this IServiceCollection services) + { + services.TryAddSingleton(); + return services; + } + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/MediatRDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/MediatRDIC.cs index da88401..39d64a9 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/MediatRDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/MediatRDIC.cs @@ -1,6 +1,5 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/PreConfigurationDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/PreConfigurationDIC.cs new file mode 100644 index 0000000..6309b80 --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/PreConfigurationDIC.cs @@ -0,0 +1,18 @@ +using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; +using Microsoft.Extensions.DependencyInjection; + +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers +{ + public class PreConfigurationDIC + { + public IServiceCollection AddWebPreConfigurations(ref IServiceCollection services) + { + + services.AddWebHostingServices(); + services.AddLoggerProviderServices(); + services.AddSingleton(); + services.AddSingleton(); + return services; + } + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/WebHostingDIC.cs b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/WebHostingDIC.cs index 16aefa1..a9000ef 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/WebHostingDIC.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/DependencyContainers/WebHostingDIC.cs @@ -1,9 +1,9 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; using System; using System.Collections.Generic; using System.Linq; @@ -11,10 +11,18 @@ using System.Threading.Tasks; public static class WebHostingDIC { - public static IServiceCollection AddWebHostingService(this IServiceCollection services) + public static IServiceCollection AddWebHostingServices(this IServiceCollection services) { + services.AddSingleton(); services.AddSingleton(); return services; } + + public static IServiceCollection TryAddWebHostingServices(this IServiceCollection services) + { + services.TryAddSingleton(); + services.TryAddSingleton(); + return services; + } } } diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAllDotNetCenterServices.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAllDotNetCenterServices.cs index 21ae863..d560007 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAllDotNetCenterServices.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAllDotNetCenterServices.cs @@ -1,4 +1,4 @@ -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { public interface SupportAllDotNetCenterServices { diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAutoMapper.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAutoMapper.cs index a082ee6..f2a5714 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAutoMapper.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportAutoMapper.cs @@ -1,4 +1,4 @@ -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { using global::AutoMapper; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportConfiguration.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportConfiguration.cs index a89cab5..24f0fc5 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportConfiguration.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportConfiguration.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Configuration; -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { public interface SupportConfiguration { diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportDateTime.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportDateTime.cs index 1c5ff32..5037d0b 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportDateTime.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportDateTime.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { public interface SupportDateTime where TAppDateTimeNowService : CompoundableDateTimeNow diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportHttpContextServices.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportHttpContextServices.cs index 897087e..f6517b1 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportHttpContextServices.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportHttpContextServices.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.Http; -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { public interface SupportHttpContextServices { diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggerProviders.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggerProviders.cs new file mode 100644 index 0000000..acb9abb --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggerProviders.cs @@ -0,0 +1,8 @@ +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices +{ + using Microsoft.Extensions.Logging; + public interface SupportLoggerProviders + { + public ILoggerFactory Factory { get; } + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggingServices.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggingServices.cs index 9a01001..1a1548e 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggingServices.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportLoggingServices.cs @@ -1,18 +1,9 @@ -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using DotNetCenter.Beyond.Web.Core.Common; - using DotNetCenter.Beyond.Web.Core.Controllers; - using Microsoft.AspNetCore.Http; - using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; public interface SupportLoggingServices - where TController : ProcessableEntry +where TController : ProcessableEntry { public ILogger Logger { get; } } diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportMediateR.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportMediateR.cs index 05948f6..9737f12 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportMediateR.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportMediateR.cs @@ -1,5 +1,5 @@ using MediatR; -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { public interface SupportMediateR { diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportPreConfiguration.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportPreConfiguration.cs new file mode 100644 index 0000000..5623229 --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportPreConfiguration.cs @@ -0,0 +1,10 @@ +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices +{ + using Microsoft.Extensions.Logging; + public interface SupportPreConfiguration + { + public SupportLoggerProviders LoggerProviders { get; } + public SupportWebHosting WebHosting { get; } + public SupportConfiguration Configuration { get; } + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportWebHosting.cs b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportWebHosting.cs index 001e2a8..6086fb2 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportWebHosting.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Interfaces/SupportWebHosting.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices { /// /// #### diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/AllDotNetCenterServices.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/AllDotNetCenterServices.cs index 7366436..e7f2b9a 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/AllDotNetCenterServices.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/AllDotNetCenterServices.cs @@ -1,4 +1,4 @@ -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/AutoMapperService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/AutoMapperService.cs index c078e06..5364068 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/AutoMapperService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/AutoMapperService.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using Microsoft.AspNetCore.Http; namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services { diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/ConfigurationService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/ConfigurationService.cs index 542ae9d..9a22dce 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/ConfigurationService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/ConfigurationService.cs @@ -1,4 +1,4 @@ -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using System; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/DateTimeService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/DateTimeService.cs index d8ba23c..ebbdeee 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/DateTimeService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/DateTimeService.cs @@ -1,4 +1,4 @@ -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using Microsoft.AspNetCore.Http; using System; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/HttpContextServices.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/HttpContextServices.cs index 8d7db97..5e6ebe4 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/HttpContextServices.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/HttpContextServices.cs @@ -1,17 +1,10 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services { - using Microsoft.Extensions.DependencyInjection; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using Microsoft.AspNetCore.Http; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; public class HttpContextServices : SupportHttpContextServices { #region Constructor - public HttpContextServices(IHttpContextAccessor httpContextAccessor) + public HttpContextServices(IHttpContextAccessor httpContextAccessor) => _httpContextAccessor = httpContextAccessor; #endregion diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/LoggerProviderService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/LoggerProviderService.cs new file mode 100644 index 0000000..f295cfd --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/LoggerProviderService.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using DotNetCenter.Beyond.Web.Core.Controllers; +using Microsoft.AspNetCore.Mvc.RazorPages; +using DotNetCenter.Beyond.Web.Core.Common; +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services +{ + public class LoggerProviderService + : SupportLoggerProviders + { + #region Constructor + public LoggerProviderService(ILoggerFactory factory) + => _factory = factory; + #endregion + + public ILoggerFactory Factory => _factory; + private readonly ILoggerFactory _factory; + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/LoggingService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/LoggingService.cs index 9ba9166..10adefa 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/LoggingService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/LoggingService.cs @@ -1,5 +1,4 @@ -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/MediateRService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/MediateRService.cs index 2a7eb24..f7e5ed1 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/MediateRService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/MediateRService.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Http; -using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services { public class MediateRService diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/PreConfigurationService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/PreConfigurationService.cs new file mode 100644 index 0000000..f4b41cc --- /dev/null +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/PreConfigurationService.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using DotNetCenter.Beyond.Web.Core.Controllers; +using Microsoft.AspNetCore.Mvc.RazorPages; +using DotNetCenter.Beyond.Web.Core.Common; +namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services +{ + public class PreConfigurationService + : SupportPreConfiguration + { + #region Constructor + public PreConfigurationService(SupportConfiguration configuration, + SupportWebHosting webHosting, + SupportLoggerProviders loggerProviders) + { + _configuraion = configuration; + _loggerProviders = loggerProviders; + _webHosting = webHosting; + } + #endregion + + public SupportConfiguration Configuration => _configuraion; + private readonly SupportConfiguration _configuraion; + + public SupportLoggerProviders LoggerProviders => _loggerProviders; + private readonly SupportLoggerProviders _loggerProviders; + + public SupportWebHosting WebHosting => _webHosting; + private readonly SupportWebHosting _webHosting; + } +} diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingService.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingService.cs index be31288..301585b 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingService.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingService.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingServiceWrapper.cs b/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingServiceWrapper.cs index 6294fd2..fcfe6be 100644 --- a/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingServiceWrapper.cs +++ b/src/Web/Core/Source/Common/DIContainerServices/Services/WebHostingServiceWrapper.cs @@ -1,6 +1,5 @@ namespace DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Web/Core/Source/Extensions/CommonServiceCollectionExtension.cs b/src/Web/Core/Source/Extensions/CommonServiceCollectionExtension.cs index fdd1e63..ae10e85 100644 --- a/src/Web/Core/Source/Extensions/CommonServiceCollectionExtension.cs +++ b/src/Web/Core/Source/Extensions/CommonServiceCollectionExtension.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Extensions { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/Web/Core/Source/Extensions/Hosting/CommonWebHostBuilderExtension.cs b/src/Web/Core/Source/Extensions/Hosting/CommonWebHostBuilderExtension.cs index 01547bb..cc43dfd 100644 --- a/src/Web/Core/Source/Extensions/Hosting/CommonWebHostBuilderExtension.cs +++ b/src/Web/Core/Source/Extensions/Hosting/CommonWebHostBuilderExtension.cs @@ -8,23 +8,25 @@ using System.Net; using System.Text; using System.Threading.Tasks; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.DependencyContainers; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; public static class CommonWebHostBuilderExtension { - public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( + public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( string envName , string contentRootPath , string webHostBuilderBasePath , string[] args) - where TStartup : class, IAppStartup + where TStartup : class, + IAppStartup { return new WebHostBuilder() .UseContentRoot(contentRootPath) @@ -33,9 +35,13 @@ string envName .UseDefaultKestrel() .UseIISIntegration() .ConfigureDefaultLogging() + .ConfigureServices((hostContext) => + { + new PreConfigurationDIC().AddWebPreConfigurations(ref hostContext); + }) .UseStartup(); } - public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( + public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( string envName , string contentRootPath , string webHostBuilderBasePath @@ -52,7 +58,7 @@ string envName , int limitKeepAliveTimeout = 30 , int RequestHeadersTimeout = 30 ) - where TStartup : class , IAppStartup + where TStartup : class , IAppStartup { return new WebHostBuilder() .UseContentRoot(contentRootPath) @@ -72,6 +78,10 @@ string envName RequestHeadersTimeout) .UseIISIntegration() .ConfigureDefaultLogging() + .ConfigureServices((hostContext) => + { + new PreConfigurationDIC().AddWebPreConfigurations(ref hostContext); + }) .UseStartup(); } } diff --git a/src/Web/Core/Source/Extensions/Hosting/Kestrel/DefaultKestrelExtension.cs b/src/Web/Core/Source/Extensions/Hosting/Kestrel/DefaultKestrelExtension.cs index 7347b09..c9fdeef 100644 --- a/src/Web/Core/Source/Extensions/Hosting/Kestrel/DefaultKestrelExtension.cs +++ b/src/Web/Core/Source/Extensions/Hosting/Kestrel/DefaultKestrelExtension.cs @@ -6,7 +6,6 @@ using System.Net; using System.Text; using System.Threading.Tasks; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; using DotNetCenter.Beyond.Web.Core.Common; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -51,7 +50,7 @@ this IWebHostBuilder host return host; } - public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( + public static IWebHostBuilder CreateDotNetCenterWebHostBuilder( string envName , string contentRootPath , string webHostBuilderBasePath @@ -67,8 +66,7 @@ string envName , int minResponseDataRateGracePeriod = 10 ) where TStartup : - class - , IAppStartup + class, IAppStartup { return new WebHostBuilder() .UseContentRoot(contentRootPath) diff --git a/src/Web/Core/Source/Middlewares/DefaultRazorpagesMiddlewareExtension.cs b/src/Web/Core/Source/Middlewares/DefaultRazorpagesMiddlewareExtension.cs index 96002ce..b58140c 100644 --- a/src/Web/Core/Source/Middlewares/DefaultRazorpagesMiddlewareExtension.cs +++ b/src/Web/Core/Source/Middlewares/DefaultRazorpagesMiddlewareExtension.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Middlewares { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Logging; @@ -9,9 +9,10 @@ using System.Text; public static class DefaultRazorpagesMiddlewareExtension { - public static IApplicationBuilder UseWeb(this IApplicationBuilder app, SupportWebHosting env, ILoggerFactory logger) + public static IApplicationBuilder UseWeb(this IApplicationBuilder app, SupportPreConfiguration preConfiguration) { - app.UseStopWatchMiddleware(env, logger); + var env = preConfiguration.WebHosting; + app.UseStopWatchMiddleware(preConfiguration); app.UseExceptionMiddleware(env); diff --git a/src/Web/Core/Source/Middlewares/ExceptionMiddleware.cs b/src/Web/Core/Source/Middlewares/ExceptionMiddleware.cs index 891973d..fb0016f 100644 --- a/src/Web/Core/Source/Middlewares/ExceptionMiddleware.cs +++ b/src/Web/Core/Source/Middlewares/ExceptionMiddleware.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; public static class ExceptionMiddleware { diff --git a/src/Web/Core/Source/Middlewares/StopWatchMiddleware.cs b/src/Web/Core/Source/Middlewares/StopWatchMiddleware.cs index dc7909f..8c76c5d 100644 --- a/src/Web/Core/Source/Middlewares/StopWatchMiddleware.cs +++ b/src/Web/Core/Source/Middlewares/StopWatchMiddleware.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Core.Middlewares { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; @@ -12,9 +12,10 @@ public static class StopWatchMiddleware { public static IApplicationBuilder UseStopWatchMiddleware( this IApplicationBuilder app, - SupportWebHosting env, - ILoggerFactory loggerFactory) + SupportPreConfiguration preConfiguration) { + var env = preConfiguration.WebHosting; + var loggerFactory = preConfiguration.LoggerProviders.Factory; if (env.Service.IsDevelopment()) app.Use(async (context, next) => { diff --git a/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs b/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs index 528633b..d6ddeac 100644 --- a/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs +++ b/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs @@ -5,9 +5,6 @@ namespace DotNetCenter.Beyond.Web.Identity.Core.Managers { - public interface SignInManagerService : SignInManagerService - { - } public interface SignInManagerService where TAppUser : IAppUser { diff --git a/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs b/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs index 85c3e26..9461f42 100644 --- a/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs +++ b/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs @@ -8,8 +8,7 @@ namespace DotNetCenter.Beyond.Web.Identity.Core.Managers { public interface UserManagerService : UserManagerService - { - } + { } public interface UserManagerService where TAppUser : IAppUser { diff --git a/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs b/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs index ee6f32b..ea3ceb6 100644 --- a/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs +++ b/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs @@ -11,12 +11,13 @@ namespace DotNetCenter.Beyond.Web.Identity.Core.DependencyResolution { public static class ManagerServicesDIC { - public static IServiceCollection AddManagerServices(this IServiceCollection services) - where TUserManager : class, UserManagerService - where TSignInManager : class, SignInManagerService + public static IServiceCollection AddManagerServices(this IServiceCollection services) + where TUserManager : class, UserManagerService + where TSignInManager : class, SignInManagerService + where TAppUser : AppUser { - services.AddSingleton, TUserManager>(); - services.AddSingleton, TSignInManager>(); + services.AddSingleton, TUserManager>(); + services.AddSingleton, TSignInManager>(); return services; } } diff --git a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs index 3b61eb0..8f5a55d 100644 --- a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs +++ b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs @@ -10,9 +10,17 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using DotNetCenter.Beyond.Web.Identity.Core.Models; - public abstract class BaseIdentityDbContext - : IdentityDbContext - where TContext : IdentityDbContext + public abstract class BaseIdentityDbContext + + : IdentityDbContext + where TContext : IdentityDbContext + where TAppUser : AppUser + where TAppRole : AppRole + where TAppUserClaim : AppUserClaim + where TUserRole : AppUserRole + where TUserLogin : AppUserLogin + where TRoleClaim : AppRoleClaim + where TUserToken : AppUserToken , new() { public BaseIdentityDbContext() { } diff --git a/src/Web/Identity/Services/Source/BaseCurrentUserService.cs b/src/Web/Identity/Services/Source/BaseCurrentUserService.cs index 80cef36..0b5fbc0 100644 --- a/src/Web/Identity/Services/Source/BaseCurrentUserService.cs +++ b/src/Web/Identity/Services/Source/BaseCurrentUserService.cs @@ -7,12 +7,19 @@ using DotNetCenter.Beyond.Web.Identity.Core.Models; using Microsoft.AspNetCore.Http; - public abstract class BaseCurrentUserService + public abstract class BaseCurrentUserService : CurrentUserService + #region Constraints + //dc#1# developer: development cases + //Case 2 : For SwitchContects internal + where TAppUser : AppUser + //Case 1 : For SwitchContects of Code To Generic Types + //where TAppUser : class, IAppUser + #endregion { public BaseCurrentUserService(IHttpContextAccessor httpContextAccessor) => HttpContextAccessor = httpContextAccessor; - public abstract IAppUser TryGetUser(out IAppUser user); + public abstract TAppUser TryGetUser(out TAppUser user); public bool TrySetUsername() { var userName = HttpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name); diff --git a/src/Web/Identity/Services/Source/BaseIdentityService.cs b/src/Web/Identity/Services/Source/BaseIdentityService.cs index 47c265a..36d3264 100644 --- a/src/Web/Identity/Services/Source/BaseIdentityService.cs +++ b/src/Web/Identity/Services/Source/BaseIdentityService.cs @@ -56,7 +56,6 @@ public virtual async Task DeleteCurrentUserAsync() var result = await _userManager.DeleteAsync(user); return result.ToApplicationResult(); } - public async Task<(ResultContainer Result, Guid UserId)> CreateUserAsync(string userName, string password) { var user = new AppUser(Guid.NewGuid(), DateTime.UtcNow) diff --git a/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs b/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs index 2955dc1..764bccd 100644 --- a/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs +++ b/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs @@ -12,17 +12,24 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - public abstract class BaseAppSignInManager - : SignInManager, SignInManagerService + public abstract class BaseAppSignInManager + : SignInManager, SignInManagerService + #region Constraints + //dc#1# developer: development cases + //Case 2 : For SwitchContects internal + where TAppUser : AppUser + //Case 1 : For SwitchContects of Code To Generic Types + //where TAppUser : class, IAppUser + #endregion { protected BaseAppSignInManager( - UserManager userManager, + UserManager userManager, IHttpContextAccessor contextAccessor, - IUserClaimsPrincipalFactory claimsFactory, + IUserClaimsPrincipalFactory claimsFactory, IOptions optionsAccessor, - ILogger logger, + ILogger> logger, IAuthenticationSchemeProvider schemes, - IUserConfirmation confirmation) + IUserConfirmation confirmation) : base( userManager, contextAccessor, diff --git a/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs b/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs index 39e5365..a5a9152 100644 --- a/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs +++ b/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs @@ -15,18 +15,25 @@ using DotNetCenter.Core.ErrorHandlers; using DotNetCenter.Beyond.Web.Identity.Core.Managers; - public abstract class BaseAppUserManager - : UserManager, UserManagerService + public abstract class BaseAppUserManager + : UserManager, UserManagerService + #region Constraints + //dc#1# developer: development cases + //Case 2 : For SwitchContects internal + where TAppUser : AppUser + //Case 1 : For SwitchContects of Code To Generic Types + //where TAppUser : class, IAppUser + #endregion { - protected BaseAppUserManager(IUserStore store, + protected BaseAppUserManager(IUserStore store, IOptions optionsAccessor, - IPasswordHasher passwordHasher, - IEnumerable> userValidators, - IEnumerable> passwordValidators, + IPasswordHasher passwordHasher, + IEnumerable> userValidators, + IEnumerable> passwordValidators, ILookupNormalizer keyNObjRelMappingalizer, IdentityErrorDescriber errors, IServiceProvider services, - ILogger logger) + ILogger> logger) : base(store, optionsAccessor, passwordHasher, @@ -38,7 +45,7 @@ protected BaseAppUserManager(IUserStore store, logger) { } - public new async Task CreateAsync(IAppUser user) + public new async Task CreateAsync(TAppUser user) { var idResult = await base.CreateAsync(user); return idResult.ToApplicationResult(); diff --git a/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs b/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs index 8802ad0..04e8560 100644 --- a/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs +++ b/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs @@ -13,9 +13,13 @@ namespace DotNetCenter.Beyond.Web.Identity.Services using System.Security.Claims; using System.Threading; using System.Threading.Tasks; - public class RevalidatingIdentityAuthenticationStateProvider + public class RevalidatingIdentityAuthenticationStateProvider : RevalidatingServerAuthenticationStateProvider - where TUser : IAppUser + //dc#1# developer: development cases + //Case 2 : For SwitchContects internal + where TAppUser : AppUser + //Case 1 : For SwitchContects of Code To Generic Types + //where TAppUser : class, IAppUser { private readonly IServiceScopeFactory _scopeFactory; private readonly IdentityOptions _options; diff --git a/src/Web/Identity/Services/Source/UserAuthenticationService.cs b/src/Web/Identity/Services/Source/UserAuthenticationService.cs index 4897e8a..a52f1bd 100644 --- a/src/Web/Identity/Services/Source/UserAuthenticationService.cs +++ b/src/Web/Identity/Services/Source/UserAuthenticationService.cs @@ -26,6 +26,7 @@ public UserAuthenticationService( IdentityDbService context, IdentityService identityService, CurrentUserService currentUserService, +//#??must confugured for dep inj UserManagerService userManager, SignInManagerService signInManager) { diff --git a/src/Web/Mvc/RazorPages/Source/Pages/BasePageModel.cs b/src/Web/Mvc/RazorPages/Source/Pages/BasePageModel.cs index 402d481..447ae6c 100644 --- a/src/Web/Mvc/RazorPages/Source/Pages/BasePageModel.cs +++ b/src/Web/Mvc/RazorPages/Source/Pages/BasePageModel.cs @@ -7,7 +7,7 @@ using DotNetCenter.DateTime.Common; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Http; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.PageModels; public abstract class BasePageModel diff --git a/src/Web/Mvc/RazorPages/Source/Pages/BaseRazorPage.cs b/src/Web/Mvc/RazorPages/Source/Pages/BaseRazorPage.cs index e801d54..95d5bca 100644 --- a/src/Web/Mvc/RazorPages/Source/Pages/BaseRazorPage.cs +++ b/src/Web/Mvc/RazorPages/Source/Pages/BaseRazorPage.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Http; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.PageModels; using Microsoft.AspNetCore.Mvc.Razor.Extensions; diff --git a/src/Web/Mvc/Source/Controllers/BaseController.cs b/src/Web/Mvc/Source/Controllers/BaseController.cs index 5e8f253..24c5003 100644 --- a/src/Web/Mvc/Source/Controllers/BaseController.cs +++ b/src/Web/Mvc/Source/Controllers/BaseController.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using DotNetCenter.Beyond.Web.Core.Controllers; using Microsoft.AspNetCore.Http; - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Controllers.Generic; using DotNetCenter.DateTime.Common; diff --git a/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationManagerDIC.cs b/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationManagerDIC.cs index f5c7749..3ef733c 100644 --- a/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationManagerDIC.cs +++ b/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationManagerDIC.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using DotNetCenter.Beyond.Web.Projects.Configuration.Core.Interfaces; using DotNetCenter.Beyond.Web.Projects.Configuration.Core.Services; + using Microsoft.Extensions.DependencyInjection.Extensions; public static class ConfigurationManagerDIC { @@ -21,5 +22,16 @@ public static IServiceCollection AddConfigurationManagerServices(this IServiceCo return services; } + public static IServiceCollection TryAddConfigurationManagerServices(this IServiceCollection services) + { + services + .TryAddConfigurationsCoreServices(); + services + .TryAddTransient(); + services + .TryAddTransient(); + + return services; + } } } diff --git a/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationsCoreDIC.cs b/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationsCoreDIC.cs index acdf810..3e57ab1 100644 --- a/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationsCoreDIC.cs +++ b/src/Web/Projects/Configuration/Core/Source/DIContainerServices/ConfigurationsCoreDIC.cs @@ -12,5 +12,9 @@ public static IServiceCollection AddConfigurationsCoreServices(this IServiceColl { return services; } + public static IServiceCollection TryAddConfigurationsCoreServices(this IServiceCollection services) + { + return services; + } } } diff --git a/src/Web/Projects/Configuration/Core/Source/Interfaces/ConfigurationServices.cs b/src/Web/Projects/Configuration/Core/Source/Interfaces/ConfigurationServices.cs index b6ac448..6d386c1 100644 --- a/src/Web/Projects/Configuration/Core/Source/Interfaces/ConfigurationServices.cs +++ b/src/Web/Projects/Configuration/Core/Source/Interfaces/ConfigurationServices.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Projects.Configuration.Core { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; using DotNetCenter.Beyond.Web.Projects.Configuration.Core.Interfaces; using Microsoft.Extensions.Configuration; using System; diff --git a/src/Web/Projects/Configuration/Core/Source/Services/BaseConfigService.cs b/src/Web/Projects/Configuration/Core/Source/Services/BaseConfigService.cs index 0f5cf3a..c5fd0d5 100644 --- a/src/Web/Projects/Configuration/Core/Source/Services/BaseConfigService.cs +++ b/src/Web/Projects/Configuration/Core/Source/Services/BaseConfigService.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Projects.Configuration.Core.Services { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Projects.Configuration.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; @@ -10,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection; using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using Microsoft.AspNetCore.Http; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; public abstract class BaseConfigService : ConfigurationServices diff --git a/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationManagerService.cs b/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationManagerService.cs index c1d021d..33ef561 100644 --- a/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationManagerService.cs +++ b/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationManagerService.cs @@ -1,6 +1,6 @@ namespace DotNetCenter.Beyond.Web.Projects.Configuration.Core.Services { - using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Interfaces; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices.Services; using DotNetCenter.Beyond.Web.Projects.Configuration.Core.Interfaces; using Microsoft.AspNetCore.Http; @@ -13,6 +13,8 @@ using Microsoft.Extensions.Configuration; using System.IO; using Microsoft.AspNetCore.Hosting; + using DotNetCenter.Beyond.Web.Core.Common.DIContainerServices; + public class ConfigurationManagerService : BaseConfigService , SupportConfigurationManager diff --git a/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationServiceCollectionServices.cs b/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationServiceCollectionServices.cs index ba84107..b7858f1 100644 --- a/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationServiceCollectionServices.cs +++ b/src/Web/Projects/Configuration/Core/Source/Services/ConfigurationServiceCollectionServices.cs @@ -8,13 +8,19 @@ using System.Text; using System.Threading.Tasks; using DotNetCenter.Beyond.Web.Core.Extensions; + using DotNetCenter.Beyond.Web.Projects.Configuration.Core.DIContainerServices; + public static class ConfigurationServiceCollectionServices { public static void UpdateGetConfigurationManager( this IServiceCollection services, out SupportConfigurationManager configurationManagerService) { + + services.CreateServiceProviderScope(out var serviceProvider, out var scope); + services.TryAddConfigurationManagerServices(); + configurationManagerService = serviceProvider .GetRequiredService(); } From 791bdadbde8eeac90410dbed5231052c7644e6b4 Mon Sep 17 00:00:00 2001 From: arsalan falahpour Date: Fri, 9 Jul 2021 14:03:17 +0430 Subject: [PATCH 2/5] Change Version --- src/Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a470a13..cc18971 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -18,9 +18,9 @@ latest https://github.com/arsalanfallahpour/DotNetCenter.Beyond.git - 0.2.5 - 0.2.5 - 0.2.5 + 0.2.6 + 0.2.6 + 0.2.6 3.3.2 3.9.0-2.final From 15d46a20e1e61ccff03f6f238a2ba4673ae2d1b9 Mon Sep 17 00:00:00 2001 From: Arsalan Fallahpour Date: Thu, 2 Sep 2021 07:13:27 -0700 Subject: [PATCH 3/5] Stable Bugfixed --- src/Directory.Build.props | 8 +- ...tCenter.Beyond.Mediation.Behaviours.csproj | 3 + .../Behaviours/Source/RequestLogger.cs | 17 +- .../Source/RequestPerformanceBehaviour.cs | 19 +- .../Source/Auditing/AuditableDbService.cs | 3 +- .../Source/Auditing/BaseAuditableDbContext.cs | 9 +- .../Core/Source/DbContext/BaseDbContext.cs | 25 ++- .../Core/Source/DbContext/DbService.cs | 8 +- .../Core/Source/DbInitializer.cs | 6 +- ...NetCenter.Beyond.ObjRelMapping.Core.csproj | 6 +- .../Source/Infrastructure/Common/IAppUser.cs | 18 ++ .../Common/IDataAccessObject.cs | 12 ++ .../Common/InfrastructureDao.cs | 11 + .../Common/PersistableObject.cs | 11 + .../Infrastructure/Common/TrackableEntity.cs | 6 + .../Configuration/AppConfiguration.cs | 15 ++ .../Configuration/BaseDataAccessObject.cs | 16 ++ .../Configuration/BaseEntityConfiguration.cs | 195 ++++++++++++++++++ .../Core/Source/Repository/BaseRepository.cs | 6 +- .../Source/Repository/RepositoryService.cs | 2 +- .../Core/Source/Presenters/BasePresenter.cs | 6 +- .../ViewComponents/BaseViewComponent.cs | 4 +- .../Common/Interfaces/CurrentUserService.cs | 13 -- .../Common/Interfaces/IdentityService.cs | 12 -- .../Common/Interfaces/TrackableEntity.cs | 6 - .../Core/Source/Common/Models/AppRole.cs | 41 ---- .../Core/Source/Common/Models/AppRoleClaim.cs | 14 -- .../Core/Source/Common/Models/AppUser.cs | 130 ------------ .../Core/Source/Common/Models/AppUserClaim.cs | 14 -- .../Core/Source/Common/Models/AppUserRole.cs | 39 ---- .../Core/Source/Common/Models/AppUserToken.cs | 10 - .../Core/Source/Common/Models/IAppRole.cs | 12 -- .../Source/Common/Models/IAppRoleClaim.cs | 6 - .../Core/Source/Common/Models/IAppUser.cs | 24 --- .../Source/Common/Models/IAppUserClaim.cs | 6 - .../Source/Common/Models/IAppUserLogin.cs | 6 - .../Core/Source/Common/Models/IAppUserRole.cs | 9 - .../Source/Common/Models/IAppUserToken.cs | 6 - ...tNetCenter.Beyond.Web.Identity.Core.csproj | 5 +- .../Configurations/AppRoleClaimConfig.cs | 20 -- .../Model/Configurations/AppUserConfig.cs | 29 --- .../Model/Configurations/AppUserRoleConfig.cs | 20 -- ...b.Identity.Infrastructure.SqlServer.csproj | 5 + .../Source/Common/BasePersistentObject.cs | 21 ++ .../Configurations/AppRoleClaimConfig.cs | 28 +++ .../Common}/Configurations/AppRoleConfig.cs | 6 +- .../Configurations/AppUserClaimConfig.cs | 3 +- .../Common/Configurations/AppUserConfig.cs | 51 +++++ .../Configurations/AppUserLoginConfig.cs | 4 +- .../Configurations/AppUserRoleConfig.cs | 27 +++ .../Configurations/AppUserTokenConfig.cs | 4 +- .../Source/Common/Models/AppRole.cs | 26 +++ .../Source/Common/Models/AppRoleClaim.cs | 19 ++ .../Source/Common/Models/AppUser.cs | 15 ++ .../Source/Common/Models/AppUserClaim.cs | 19 ++ .../Source/Common/Models/AppUserLogin.cs | 4 +- .../Source/Common/Models/AppUserRole.cs | 11 + .../Source/Common/Models/AppUserToken.cs | 11 + .../Source/Common/Models/IAppRole.cs | 13 ++ .../Source/Common/Models/IAppRoleClaim.cs | 8 + .../Source/Common/Models/IAppUserClaim.cs | 8 + .../Source/Common/Models/IAppUserLogin.cs | 6 + .../Source/Common/Models/IAppUserRole.cs | 11 + .../Source/Common/Models/IAppUserToken.cs | 6 + .../Source/Common/Models/IIdentityUser.cs | 18 ++ .../Source/DbContextServices/Auditor.cs | 38 ---- .../BaseIdentityDbContext.cs | 122 ++++++++--- .../DbContextServices/IdentityDbService.cs | 3 +- .../Source/DependencyResolution/AuditorDIC.cs | 14 -- ...r.Beyond.Web.Identity.ObjRelMapping.csproj | 9 +- src/Web/Identity/Services/Source/Auditor.cs | 59 ++++++ .../Services/Source/BaseCurrentUserService.cs | 51 ++--- .../Services/Source/BaseIdentityService.cs | 48 ++--- .../Services/Source/CurrentUserService.cs | 14 ++ .../Source/DependencyResolution/AuditorDIC.cs | 20 ++ .../IdentityDbServicesDIC.cs | 7 +- .../IdentityServicesDIC.cs | 16 -- .../ManagerServicesDIC.cs | 13 +- ...Center.Beyond.Web.Identity.Services.csproj | 1 + .../Services/Source/IdentityService.cs | 14 ++ .../Source/Managers/BaseAppSignInManager.cs | 3 +- .../Source/Managers/BaseAppUserManager.cs | 3 +- .../Source}/Managers/SignInManagerService.cs | 6 +- .../Source}/Managers/UserManagerService.cs | 8 +- ...tingIdentityAuthenticationStateProvider.cs | 8 +- .../Source/UserAuthenticationService.cs | 72 +++---- 86 files changed, 998 insertions(+), 683 deletions(-) create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Common/IAppUser.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Common/IDataAccessObject.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Common/InfrastructureDao.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Common/PersistableObject.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Common/TrackableEntity.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Configuration/AppConfiguration.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseDataAccessObject.cs create mode 100644 src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseEntityConfiguration.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Interfaces/CurrentUserService.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Interfaces/IdentityService.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Interfaces/TrackableEntity.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppRole.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppRoleClaim.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppUser.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppUserClaim.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppUserRole.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/AppUserToken.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppRole.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppRoleClaim.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppUser.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppUserClaim.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppUserLogin.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppUserRole.cs delete mode 100644 src/Web/Identity/Core/Source/Common/Models/IAppUserToken.cs delete mode 100644 src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleClaimConfig.cs delete mode 100644 src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserConfig.cs delete mode 100644 src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserRoleConfig.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/BasePersistentObject.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs rename src/Web/Identity/{Infrastructure/SqlServer/Source/Common/Model => ObjRelMapping/Source/Common}/Configurations/AppRoleConfig.cs (85%) rename src/Web/Identity/{Infrastructure/SqlServer/Source/Common/Model => ObjRelMapping/Source/Common}/Configurations/AppUserClaimConfig.cs (77%) create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserConfig.cs rename src/Web/Identity/{Infrastructure/SqlServer/Source/Common/Model => ObjRelMapping/Source/Common}/Configurations/AppUserLoginConfig.cs (69%) create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs rename src/Web/Identity/{Infrastructure/SqlServer/Source/Common/Model => ObjRelMapping/Source/Common}/Configurations/AppUserTokenConfig.cs (70%) create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRole.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRoleClaim.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUser.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserClaim.cs rename src/Web/Identity/{Core => ObjRelMapping}/Source/Common/Models/AppUserLogin.cs (54%) create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserRole.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRole.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRoleClaim.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserClaim.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserLogin.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserRole.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserToken.cs create mode 100644 src/Web/Identity/ObjRelMapping/Source/Common/Models/IIdentityUser.cs delete mode 100644 src/Web/Identity/ObjRelMapping/Source/DbContextServices/Auditor.cs delete mode 100644 src/Web/Identity/ObjRelMapping/Source/DependencyResolution/AuditorDIC.cs create mode 100644 src/Web/Identity/Services/Source/Auditor.cs create mode 100644 src/Web/Identity/Services/Source/CurrentUserService.cs create mode 100644 src/Web/Identity/Services/Source/DependencyResolution/AuditorDIC.cs rename src/Web/Identity/{ObjRelMapping => Services}/Source/DependencyResolution/IdentityDbServicesDIC.cs (64%) delete mode 100644 src/Web/Identity/Services/Source/DependencyResolution/IdentityServicesDIC.cs rename src/Web/Identity/{Core => Services}/Source/DependencyResolution/ManagerServicesDIC.cs (64%) create mode 100644 src/Web/Identity/Services/Source/IdentityService.cs rename src/Web/Identity/{Core/Source/Common => Services/Source}/Managers/SignInManagerService.cs (77%) rename src/Web/Identity/{Core/Source/Common => Services/Source}/Managers/UserManagerService.cs (89%) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index cc18971..0beec4a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -18,9 +18,9 @@ latest https://github.com/arsalanfallahpour/DotNetCenter.Beyond.git - 0.2.6 - 0.2.6 - 0.2.6 + 0.2.11 + 0.2.11 + 0.2.11 3.3.2 3.9.0-2.final @@ -79,7 +79,7 @@ 0.2.1 - 0.2.2 + 0.2.6 0.2.2 8.1.1 diff --git a/src/Mediation/Behaviours/Source/DotNetCenter.Beyond.Mediation.Behaviours.csproj b/src/Mediation/Behaviours/Source/DotNetCenter.Beyond.Mediation.Behaviours.csproj index 2386553..77089ed 100644 --- a/src/Mediation/Behaviours/Source/DotNetCenter.Beyond.Mediation.Behaviours.csproj +++ b/src/Mediation/Behaviours/Source/DotNetCenter.Beyond.Mediation.Behaviours.csproj @@ -72,8 +72,11 @@ + + + diff --git a/src/Mediation/Behaviours/Source/RequestLogger.cs b/src/Mediation/Behaviours/Source/RequestLogger.cs index c9beff1..8341edf 100644 --- a/src/Mediation/Behaviours/Source/RequestLogger.cs +++ b/src/Mediation/Behaviours/Source/RequestLogger.cs @@ -8,17 +8,20 @@ namespace DotNetCenter.Beyond.Mediation.Behaviours using DotNetCenter.Beyond.Web.Identity.Core; using System; using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices; + using DotNetCenter.Beyond.Web.Identity.Services; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; public class RequestLogger : IRequestPreProcessor { private readonly ILogger _logger; private readonly CurrentUserService _currentUserService; - private readonly IdentityService _identityService; + private readonly IdentityService _identityService; public RequestLogger( ILogger logger, CurrentUserService currentUserService, - IdentityService identityService) + IdentityService identityService) { _logger = logger; _currentUserService = currentUserService; @@ -26,8 +29,14 @@ public RequestLogger( } public async Task Process(TRequest request, CancellationToken cancellationToken) { - var userName = await _identityService.GetUsernameAsync(_currentUserService.UserId); - _logger.LogInformation("Request: {Name} {@UserId} {@UserName} {@Request}", typeof(TRequest).Name, _currentUserService.UserId, userName, request); + int? userId = -9845; + var userName = "Not Authorized User"; + if (_currentUserService.IsUserAuthenticated()) + { + userId = _currentUserService.UserId; + userName = await _identityService.GetUsernameAsync((int)_currentUserService.UserId); + } + _logger.LogInformation("Request: {Name} {@UserId} {@UserName} {@Request}", typeof(TRequest).Name, userId, userName, request); } } } diff --git a/src/Mediation/Behaviours/Source/RequestPerformanceBehaviour.cs b/src/Mediation/Behaviours/Source/RequestPerformanceBehaviour.cs index 433340a..a084dc9 100644 --- a/src/Mediation/Behaviours/Source/RequestPerformanceBehaviour.cs +++ b/src/Mediation/Behaviours/Source/RequestPerformanceBehaviour.cs @@ -8,18 +8,23 @@ using MediatR; using System; using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; + using System.Security.Principal; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Beyond.Web.Identity.Services; + public class RequestPerfObjRelMappinganceBehaviour : IPipelineBehavior { private readonly Stopwatch _timer; private readonly ILogger _logger; private readonly CurrentUserService _currentUserService; - private readonly IdentityService _identityService; + private readonly IdentityService _identityService; public RequestPerfObjRelMappinganceBehaviour( ILogger logger, CurrentUserService currentUserService, - IdentityService identityService) + IdentityService identityService) { _timer = new Stopwatch(); _logger = logger; @@ -49,17 +54,17 @@ private async Task LogRequestLongRunning(TRequest request) { var logMessage = "Application Long Running Request: {Name} ({ElapsedMilliseconds} milliseconds) {@UserId}"; var requestName = typeof(TRequest).Name; - if (_currentUserService.TrySetUserId()) + //if (_currentUserService.TrySetUserId()) await LogCriticalWithUserName(request, _timer.ElapsedMilliseconds, logMessage, requestName); - else - _logger.LogCritical(logMessage + "{@Request}", requestName, _timer.ElapsedMilliseconds, request); + //else + // _logger.LogCritical(logMessage + "{@Request}", requestName, _timer.ElapsedMilliseconds, request); } private async Task LogCriticalWithUserName(TRequest request, long elapsedMilliseconds, string logMessage, string requestName) { var userId = _currentUserService.UserId; - if (_currentUserService.TrySetUsername()) - _logger.LogCritical(logMessage + "{@UserName} {@Request}", requestName, elapsedMilliseconds, userId, _currentUserService.Username, request); + var username = _currentUserService?.Username ?? "UnAuthorized User %!%"; + _logger.LogCritical(logMessage + "{@UserName} {@Request}", requestName, elapsedMilliseconds, userId, username, request); } } } diff --git a/src/ObjRelMapping/Core/Source/Auditing/AuditableDbService.cs b/src/ObjRelMapping/Core/Source/Auditing/AuditableDbService.cs index 71ef2fe..95ed36f 100644 --- a/src/ObjRelMapping/Core/Source/Auditing/AuditableDbService.cs +++ b/src/ObjRelMapping/Core/Source/Auditing/AuditableDbService.cs @@ -4,10 +4,11 @@ namespace DotNetCenter.Beyond.ObjRelMapping.Core.DbContext using System; using System.Threading; using System.Threading.Tasks; - public interface AuditableDbService + public interface AuditableDbService : IDisposable, IAsyncDisposable, AuditableDbContext, EntryableDbContext, SetableDbContext { void Save(); + Task SaveAsync(); Task SaveAsync(CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Auditing/BaseAuditableDbContext.cs b/src/ObjRelMapping/Core/Source/Auditing/BaseAuditableDbContext.cs index 5b5a384..51f3c7b 100644 --- a/src/ObjRelMapping/Core/Source/Auditing/BaseAuditableDbContext.cs +++ b/src/ObjRelMapping/Core/Source/Auditing/BaseAuditableDbContext.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; public abstract class BaseAuditableDbContext : DbContext - , AuditableDbService + , AuditableDbService where TContext : DbContext { private readonly string _defaultSchema; @@ -24,15 +24,16 @@ protected override void OnModelCreating(ModelBuilder builder) { if (!string.IsNullOrEmpty(_defaultSchema) && !string.IsNullOrWhiteSpace(_defaultSchema)) builder.HasDefaultSchema(_defaultSchema); + else + builder.HasDefaultSchema("dbo"); //builder.ApplyConfigurationsFromAssembly(typeof(DatabaseService<>).Assembly); base.OnModelCreating(builder); } - public void Audit() - => _auditor.UpdateModifiedAll(ChangeTracker); + public virtual void Audit() => _auditor.UpdateModifiedAll(ChangeTracker); public abstract void Save(); - + public abstract Task SaveAsync(); public abstract Task SaveAsync(CancellationToken cancellationToken = default); } } diff --git a/src/ObjRelMapping/Core/Source/DbContext/BaseDbContext.cs b/src/ObjRelMapping/Core/Source/DbContext/BaseDbContext.cs index 4ead355..25fad02 100644 --- a/src/ObjRelMapping/Core/Source/DbContext/BaseDbContext.cs +++ b/src/ObjRelMapping/Core/Source/DbContext/BaseDbContext.cs @@ -2,28 +2,43 @@ { using DotNetCenter.Beyond.ObjRelMapping.Core.DbContext; using Microsoft.EntityFrameworkCore; + using System.Reflection; using System.Threading; using System.Threading.Tasks; - public abstract class BaseDbContext : DbContext, DbService + public abstract class BaseDbContext : DbContext, DbService where TContext : DbContext { - private readonly string _defaultSchema; - + public virtual string Schema => _defaultSchema; + public readonly string _defaultSchema; + public abstract Assembly ConfigurationAssemby { get; } + public abstract bool UseAssemblyToScanConfigurations { get; } + public abstract bool EnableSensitiveDataLogging { get; } public BaseDbContext(DbContextOptions options, string defaultSchema = "dbo") : base(options) => _defaultSchema = defaultSchema; - + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.EnableSensitiveDataLogging(UseAssemblyToScanConfigurations); + } protected override void OnModelCreating(ModelBuilder builder) { + base.OnModelCreating(builder); + if (!string.IsNullOrEmpty(_defaultSchema) && !string.IsNullOrWhiteSpace(_defaultSchema)) builder.HasDefaultSchema(_defaultSchema); + else + builder.HasDefaultSchema("dbo"); - base.OnModelCreating(builder); + + if (UseAssemblyToScanConfigurations) + builder.ApplyConfigurationsFromAssembly(ConfigurationAssemby); } public abstract void Save(); + public abstract Task SaveAsync(); public abstract Task SaveAsync(CancellationToken cancellationToken = default); } } diff --git a/src/ObjRelMapping/Core/Source/DbContext/DbService.cs b/src/ObjRelMapping/Core/Source/DbContext/DbService.cs index e5ba19b..a121970 100644 --- a/src/ObjRelMapping/Core/Source/DbContext/DbService.cs +++ b/src/ObjRelMapping/Core/Source/DbContext/DbService.cs @@ -2,11 +2,17 @@ namespace DotNetCenter.Beyond.ObjRelMapping.Core.DbContext { using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; using System; + using System.Reflection; using System.Threading; using System.Threading.Tasks; - public interface DbService : IDisposable, IAsyncDisposable, EntryableDbContext, SetableDbContext + public interface DbService: IDisposable, IAsyncDisposable, EntryableDbContext, SetableDbContext { void Save(); + Task SaveAsync(); Task SaveAsync(CancellationToken cancellationToken = default); + public string Schema { get; } + public Assembly ConfigurationAssemby { get; } + public bool UseAssemblyToScanConfigurations { get; } + public bool EnableSensitiveDataLogging { get; } } } \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/DbInitializer.cs b/src/ObjRelMapping/Core/Source/DbInitializer.cs index 5ad571e..99f10bc 100644 --- a/src/ObjRelMapping/Core/Source/DbInitializer.cs +++ b/src/ObjRelMapping/Core/Source/DbInitializer.cs @@ -1,9 +1,9 @@ namespace DotNetCenter.Beyond.ObjRelMapping.Core { using DotNetCenter.Beyond.ObjRelMapping.Core.DbContext; - public interface DbInitializer + public interface DbInitializer { - public void Initialize(DbService context); - public void SeedEverything(DbService context); + public void Initialize(DbService context); + public void SeedEverything(DbService context); } } \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/DotNetCenter.Beyond.ObjRelMapping.Core.csproj b/src/ObjRelMapping/Core/Source/DotNetCenter.Beyond.ObjRelMapping.Core.csproj index 49fa8cc..b6bad0e 100644 --- a/src/ObjRelMapping/Core/Source/DotNetCenter.Beyond.ObjRelMapping.Core.csproj +++ b/src/ObjRelMapping/Core/Source/DotNetCenter.Beyond.ObjRelMapping.Core.csproj @@ -59,6 +59,7 @@ + @@ -66,6 +67,7 @@ + @@ -74,13 +76,11 @@ + - - - diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Common/IAppUser.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Common/IAppUser.cs new file mode 100644 index 0000000..4572a61 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Common/IAppUser.cs @@ -0,0 +1,18 @@ + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common +{ + using DotNetCenter.Core.Entities; + using System; + using System.Collections.Generic; + + public interface IAppUser: InfrastructureDao, AuditableEntity, TrackableEntity + where TKeyUser : struct, IEquatable + where TKeyAuditor : struct, IEquatable + { + public string Tag { get; } + public string UserName { get; } + public string Email { get; } + public string DisplayName { get; } + //public bool ValidateIdentityUser(); + } +} \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Common/IDataAccessObject.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Common/IDataAccessObject.cs new file mode 100644 index 0000000..bab6908 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Common/IDataAccessObject.cs @@ -0,0 +1,12 @@ +using DotNetCenter.Core; +using DotNetCenter.Core.Entities; +using System; +using Sys = System; + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common +{ + public interface IDataAccessObject : Entity + where TKey : IEquatable + { + } +} \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Common/InfrastructureDao.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Common/InfrastructureDao.cs new file mode 100644 index 0000000..78924aa --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Common/InfrastructureDao.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common +{ + public interface InfrastructureDao + where TKey : IEquatable + { + } +} diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Common/PersistableObject.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Common/PersistableObject.cs new file mode 100644 index 0000000..b102964 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Common/PersistableObject.cs @@ -0,0 +1,11 @@ +using DotNetCenter.Core.Entities; +using System; + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common +{ + public interface PersistableObject : InfrastructureDao, IDataAccessObject, AuditableEntity + where TKey : struct, IEquatable + where TKeyAuditor : struct, IEquatable + { + } +} \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Common/TrackableEntity.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Common/TrackableEntity.cs new file mode 100644 index 0000000..7efb778 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Common/TrackableEntity.cs @@ -0,0 +1,6 @@ +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common +{ + public interface TrackableEntity + { + } +} diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/AppConfiguration.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/AppConfiguration.cs new file mode 100644 index 0000000..b2deae4 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/AppConfiguration.cs @@ -0,0 +1,15 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Configuration +{ + internal interface AppConfiguration + where T : class + where TKeyEntity : IEquatable + { + public void Configure(EntityTypeBuilder builder); + + } +} \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseDataAccessObject.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseDataAccessObject.cs new file mode 100644 index 0000000..ea0c1c1 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseDataAccessObject.cs @@ -0,0 +1,16 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Configuration +{ + public abstract class BaseDataAccessObject : InfrastructureDao + where TKey : IEquatable + + { + public virtual TKey Id { get; set; } + } +} diff --git a/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseEntityConfiguration.cs b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseEntityConfiguration.cs new file mode 100644 index 0000000..b28b488 --- /dev/null +++ b/src/ObjRelMapping/Core/Source/Infrastructure/Configuration/BaseEntityConfiguration.cs @@ -0,0 +1,195 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Configuration; +using DotNetCenter.Core; +using DotNetCenter.Core.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using System; +using System.ComponentModel; + +namespace DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration +{ + public abstract class BaseEntityConfiguration + : IEntityTypeConfiguration + , AppConfiguration + where T : class, Entity + where TKeyEntity : struct, IEquatable + { + // use constructor blow for single context ef apps + //public BaseAppConfigurastion(string tableName) + //{ + // _tableName = tableName; + //} + /// + /// Schema must configred in ef apps that use multi context with different schamas, + /// also all configurtins of schemas must configured on all context that used eachother entity + /// + /// + /// + /// + public BaseEntityConfiguration(string tableName, string schemaName, bool configureKey = true) + { + _tableName = tableName; + _schemaName = schemaName; + _configureKey = configureKey; + } + public BaseEntityConfiguration(bool configureKey = true) + { + _tableName = string.Empty; + _schemaName = string.Empty; + _configureKey = configureKey; + + } + public string TableName => _tableName; + private readonly string _tableName; + public string SchemaName => _schemaName; + private readonly string _schemaName; + public virtual int IdColumnSeed => 1; + public virtual int IdColumnIncrement => 1; + public bool ConfigureKey => _configureKey; + private readonly bool _configureKey; + public virtual void Configure(EntityTypeBuilder builder) + { + if (!string.IsNullOrEmpty(TableName)) + { + + if (string.IsNullOrEmpty(SchemaName)) + builder.ToTable(TableName); + else + builder.ToTable(TableName, SchemaName); + + if (_configureKey) + { + builder + .HasKey(o => o.Id); + builder + .Property(o => o.Id) +#if NET5_0 + .UseIdentityColumn(IdColumnSeed, IdColumnIncrement) +#elif NETCOREAPP3_1_OR_GREATER + .UseSqlServerIdentityColumn(IdColumnSeed, IdColumnIncrement) +#endif + .ValueGeneratedOnAdd(); + } + } + } + } + public abstract class BaseEntityConfiguration + : IEntityTypeConfiguration + , AppConfiguration + where T : class, PersistableObject + where TKeyEntity : struct, IEquatable + where TKeyUser : struct, IEquatable + where TKeyAuditor : struct, IEquatable + { + // use constructor blow for single context ef apps + //public BaseAppConfigurastion(string tableName) + //{ + // _tableName = tableName; + //} + /// + /// Schema must configred in ef apps that use multi context with different schamas, + /// also all configurtins of schemas must configured on all context that used eachother entity + /// Auditable Configuration + /// + /// + /// + /// + /// + public BaseEntityConfiguration(string tableName, string schemaName, bool includeAuditColumns = true, bool configureKey = true) + { + _tableName = tableName; + _schemaName = schemaName; + _includeAuditColumns = includeAuditColumns; + _configureKey = configureKey; + } + public BaseEntityConfiguration(bool includeAuditColumns = true, bool configureKey = true) + { + _tableName = string.Empty; + _schemaName = string.Empty; + _includeAuditColumns = includeAuditColumns; + _configureKey = configureKey; + } + public string TableName => _tableName; + private readonly string _tableName; + public string SchemaName => _schemaName; + private readonly string _schemaName; + public bool IncludeAuditColumns => _includeAuditColumns; + private readonly bool _includeAuditColumns; + public bool ConfigureKey => _configureKey; + private readonly bool _configureKey; + public virtual int IdColumnSeed => 1; + public virtual int IdColumnIncrement => 1; + public virtual void Configure(EntityTypeBuilder builder) + { + if (!string.IsNullOrEmpty(TableName)) + { + + if (string.IsNullOrEmpty(SchemaName)) + builder.ToTable(TableName); + else + builder.ToTable(TableName, SchemaName); + + } + if (_configureKey) + { + builder + .HasKey(o => o.Id); + builder + .Property(o => o.Id) +#if NET5_0 + .UseIdentityColumn(IdColumnSeed, IdColumnIncrement) +#elif NETCOREAPP3_1_OR_GREATER + .UseSqlServerIdentityColumn(IdColumnSeed, IdColumnIncrement) +#endif + .ValueGeneratedOnAdd(); + } + + //if (typeof(int) == typeof(TEntityKey) + // || typeof(short) == entityType + // || typeof(long) == entityType + // || typeof(byte) == entityType) + + var entityType = typeof(T); + var entityName = entityType.Name; + + + + if (_includeAuditColumns) + { + builder + .Property(o => o.CreatedDateTime) + .IsRequired(); + + builder + .Property(o => o.CreatedBy) + .IsRequired(true); + + + builder + .Property(o => o.ModifiedDateTime) + .IsRequired(false); + builder + .Property(o => o.ModifiedBy) + .IsRequired(false); + + } + else + IgnoreAuditColumns(builder); + + } + protected virtual void IgnoreAuditColumns(EntityTypeBuilder builder) + { + builder + .Ignore(o => o.CreatedDateTime); + builder + .Ignore(o => o.CreatedBy); + builder + .Ignore(o => o.ModifiedBy); + builder + .Ignore(o => o.ModifiedDateTime); + } + } +} \ No newline at end of file diff --git a/src/ObjRelMapping/Core/Source/Repository/BaseRepository.cs b/src/ObjRelMapping/Core/Source/Repository/BaseRepository.cs index eeec8e5..57b7f25 100644 --- a/src/ObjRelMapping/Core/Source/Repository/BaseRepository.cs +++ b/src/ObjRelMapping/Core/Source/Repository/BaseRepository.cs @@ -11,10 +11,10 @@ public class BaseRepository : RepositoryService where TKey : struct where TEntity : class, Entity - where TContext : DbService + where TContext : DbService { - protected readonly DbService _dbService; - public BaseRepository(DbService dbService) + protected readonly DbService _dbService; + public BaseRepository(TContext dbService) => _dbService = dbService; public async Task GetByIdAsync(TKey id) => await _dbService.Set().FindAsync(id); diff --git a/src/ObjRelMapping/Core/Source/Repository/RepositoryService.cs b/src/ObjRelMapping/Core/Source/Repository/RepositoryService.cs index 2fcc8ab..275fecc 100644 --- a/src/ObjRelMapping/Core/Source/Repository/RepositoryService.cs +++ b/src/ObjRelMapping/Core/Source/Repository/RepositoryService.cs @@ -10,7 +10,7 @@ public interface RepositoryService : UpdateableRepository, DeletableRepository, AddableRepository - where TContext : DbService + where TContext : DbService where TEntity : Entity where TKey : struct { diff --git a/src/Web/Core/Source/Presenters/BasePresenter.cs b/src/Web/Core/Source/Presenters/BasePresenter.cs index 28442bb..1fad129 100644 --- a/src/Web/Core/Source/Presenters/BasePresenter.cs +++ b/src/Web/Core/Source/Presenters/BasePresenter.cs @@ -9,10 +9,10 @@ public abstract class BasePresenter : ConfigurablePresenter { public BasePresenter(IHttpContextAccessor context) : base(context) => HttpContextAccessor = context; - public IMapper Mapper => _mapper ??= HttpContextAccessor.HttpContext.RequestServices.GetService(); - protected IMapper _mapper; - private IMediator _mediator; + protected IMapper Mapper => _mapper ??= HttpContextAccessor.HttpContext.RequestServices.GetService(); + private IMapper _mapper; protected IMediator Mediator => _mediator ??= HttpContextAccessor.HttpContext.RequestServices.GetService(); + private IMediator _mediator; } } diff --git a/src/Web/Core/Source/ViewComponents/BaseViewComponent.cs b/src/Web/Core/Source/ViewComponents/BaseViewComponent.cs index 7f623da..df9efc1 100644 --- a/src/Web/Core/Source/ViewComponents/BaseViewComponent.cs +++ b/src/Web/Core/Source/ViewComponents/BaseViewComponent.cs @@ -5,9 +5,9 @@ using Microsoft.Extensions.DependencyInjection; public abstract class BaseViewComponent : ConfigurableViewComponent { - private IMediator _mediator; - private IMapper _mapper; protected IMediator Mediator => _mediator ??= HttpContext.RequestServices.GetService(); + private IMediator _mediator; protected IMapper Mapper => _mapper ??= HttpContext.RequestServices.GetService(); + private IMapper _mapper; } } diff --git a/src/Web/Identity/Core/Source/Common/Interfaces/CurrentUserService.cs b/src/Web/Identity/Core/Source/Common/Interfaces/CurrentUserService.cs deleted file mode 100644 index 4cf2e97..0000000 --- a/src/Web/Identity/Core/Source/Common/Interfaces/CurrentUserService.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core -{ - using DotNetCenter.Beyond.Web.Identity.Core.Models; - using System; - public interface CurrentUserService - { - bool TrySetUsername(); - bool TrySetUserId(); - Guid UserId { get; } - string Username { get; } - public bool IsUserAuthenticated { get; } - } -} diff --git a/src/Web/Identity/Core/Source/Common/Interfaces/IdentityService.cs b/src/Web/Identity/Core/Source/Common/Interfaces/IdentityService.cs deleted file mode 100644 index 31b1cd8..0000000 --- a/src/Web/Identity/Core/Source/Common/Interfaces/IdentityService.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core -{ - using System; - using System.Threading.Tasks; - using DotNetCenter.Core.ErrorHandlers; - public interface IdentityService - { - Task GetUsernameAsync(Guid userId); - Task<(ResultContainer Result, Guid UserId)> CreateUserAsync(string userName, string password); - Task DeleteUserAsync(Guid userId); - } -} diff --git a/src/Web/Identity/Core/Source/Common/Interfaces/TrackableEntity.cs b/src/Web/Identity/Core/Source/Common/Interfaces/TrackableEntity.cs deleted file mode 100644 index 2b9764e..0000000 --- a/src/Web/Identity/Core/Source/Common/Interfaces/TrackableEntity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core -{ - public interface TrackableEntity - { - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppRole.cs b/src/Web/Identity/Core/Source/Common/Models/AppRole.cs deleted file mode 100644 index 73fb68d..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppRole.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using Microsoft.AspNetCore.Identity; - using System; - public class AppRole - : IdentityRole - , IAppRole - { - public AppRole() { } - public AppRole(string name) - => Name = name; - public AppRole(string name, string _description) - { - Name = name; - Description = _description; - } - public string Description { get; protected set; } - public string Tag { get; protected set;} - - #region Audit - public Guid LastModifiedBy => _lastModifierId; - private Guid _lastModifierId; - - public DateTime? LastModifiedDateTime => throw new NotImplementedException(); - private DateTime? _lastModifiedDateTime; - - public Guid CreatedBy => _creatorId; - private readonly Guid _creatorId; - - public DateTime CreatedDateTime => throw new NotImplementedException(); - - private readonly DateTime _createdDateTime; - - public void RegisterModifiedInformation(Guid modifierId, DateTime modifiedDateTime) - { - _lastModifierId = modifierId; - _lastModifiedDateTime = modifiedDateTime; - } - #endregion - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppRoleClaim.cs b/src/Web/Identity/Core/Source/Common/Models/AppRoleClaim.cs deleted file mode 100644 index 9a6a4bb..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppRoleClaim.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using Microsoft.AspNetCore.Identity; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - public class AppRoleClaim - : IdentityRoleClaim - , IAppRoleClaim - { - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppUser.cs b/src/Web/Identity/Core/Source/Common/Models/AppUser.cs deleted file mode 100644 index 75e6e1a..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppUser.cs +++ /dev/null @@ -1,130 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using Microsoft.AspNetCore.Identity; - using System; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - - public class AppUser : IdentityUser - , IAppUser - { - public AppUser(Guid id, DateTime createdDateTime) - { - _id = id; - _createdDateTime = createdDateTime; - } - - public virtual bool ValidateUsername() - { - if (!string.IsNullOrEmpty(_username)) - return true; - - if (ValidateIdentityUser()) - return true; - - return !string.IsNullOrEmpty(_identityUser.UserName); - } - public virtual bool ValidateEmail() - { - if (!string.IsNullOrEmpty(_email)) - return true; - - if (ValidateIdentityUser()) - return true; - - return !string.IsNullOrEmpty(_identityUser.Email); - } - - public virtual bool ValidateIdentityUser() - { - return TrySetIdentityUser(); - } - - [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] - public new Guid Id => _id; - private readonly Guid _id; - - public string PlainPassword => _plainPassword; - private readonly string _plainPassword; - public string ProfilePictureAddress { get; protected set; } = "/user/images/profile/default.png"; - public string FirstName { get; protected set; } - public string LastName { get; protected set; } - public string DisplayName { get; protected set; } - public string AccountType { get; protected set; } - public DateTime DateRegistered { get; protected set; } - public string Tag { get; protected set; } - - #region Audit - public Guid LastModifiedBy => _lastModifierId; - private Guid _lastModifierId; - - public DateTime? LastModifiedDateTime => throw new NotImplementedException(); - private DateTime? _lastModifiedDateTime; - - public Guid CreatedBy => _creatorId; - private readonly Guid _creatorId; - - public DateTime CreatedDateTime => _createdDateTime; - private readonly DateTime _createdDateTime; - - public string Username => _username; - private readonly string _username; - - public IdentityUser IdentityUser => _identityUser; - private IdentityUser _identityUser; - public string Email => _email; - private readonly string _email; - - public void RegisterModifiedInformation(Guid modifierId, DateTime modifiedDateTime) - { - _lastModifierId = modifierId; - _lastModifiedDateTime = modifiedDateTime; - } - #endregion - #region GetIdentityUser() - public virtual bool TrySetIdentityUser() - { - if (_identityUser is not null) - return true; - - var idUser = new IdentityUser(userName: this.Username) - { - Id = this.Id.ToString(), - AccessFailedCount = this.AccessFailedCount, - TwoFactorEnabled = this.TwoFactorEnabled, - SecurityStamp = this.SecurityStamp, - PhoneNumberConfirmed = this.PhoneNumberConfirmed, - PhoneNumber = this.PhoneNumber, - PasswordHash = this.PasswordHash, - UserName = this.Username, - NormalizedEmail = this.NormalizedEmail, - NormalizedUserName = this.NormalizedUserName, - ConcurrencyStamp = this.ConcurrencyStamp, - Email = this.Email, - EmailConfirmed = this.EmailConfirmed, - LockoutEnabled = this.LockoutEnabled, - LockoutEnd = this.LockoutEnd - }; - try - { - _identityUser = idUser; - } - catch (InvalidCastException ex) - { - return false; - } - catch (Exception ex) - { - return false; - } - - if (_identityUser is null) - return false; - if (string.IsNullOrEmpty(_identityUser.UserName)) - return false; - - return true; - } - #endregion - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/AppUserClaim.cs b/src/Web/Identity/Core/Source/Common/Models/AppUserClaim.cs deleted file mode 100644 index 479bc92..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppUserClaim.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using System; - using Microsoft.AspNetCore.Identity; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - public class AppUserClaim - : IdentityUserClaim - , IAppUserClaim - { - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppUserRole.cs b/src/Web/Identity/Core/Source/Common/Models/AppUserRole.cs deleted file mode 100644 index bcfb248..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppUserRole.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using Microsoft.AspNetCore.Identity; - using System; - - public class AppUserRole - : IdentityUserRole - , IAppUserRole - { - public AppUserRole(int id, DateTime createdDateTime) - { - _id = id; - _createdDateTime = createdDateTime; - } - public int Id { get => _id; } - private readonly int _id; - - #region Audit - public Guid LastModifiedBy => _lastModifierId; - private Guid _lastModifierId; - - public DateTime? LastModifiedDateTime => throw new NotImplementedException(); - private DateTime? _lastModifiedDateTime; - - public Guid CreatedBy => _creatorId; - private readonly Guid _creatorId; - - public DateTime CreatedDateTime => throw new NotImplementedException(); - - private readonly DateTime _createdDateTime; - - public void RegisterModifiedInformation(Guid modifierId, DateTime modifiedDateTime) - { - _lastModifierId = modifierId; - _lastModifiedDateTime = modifiedDateTime; - } - #endregion - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppUserToken.cs b/src/Web/Identity/Core/Source/Common/Models/AppUserToken.cs deleted file mode 100644 index c43065b..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/AppUserToken.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using Microsoft.AspNetCore.Identity; - using System; - public class AppUserToken - : IdentityUserToken - , IAppUserToken - { - } -} diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppRole.cs b/src/Web/Identity/Core/Source/Common/Models/IAppRole.cs deleted file mode 100644 index 238ada9..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppRole.cs +++ /dev/null @@ -1,12 +0,0 @@ -using DotNetCenter.Core.Entities; -using System; - -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppRole: AuditableEntity - { - public string Name { get; } - public string Description { get; } - public string Tag { get; } - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppRoleClaim.cs b/src/Web/Identity/Core/Source/Common/Models/IAppRoleClaim.cs deleted file mode 100644 index 22cdf75..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppRoleClaim.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppRoleClaim - { - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppUser.cs b/src/Web/Identity/Core/Source/Common/Models/IAppUser.cs deleted file mode 100644 index 4081ce8..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppUser.cs +++ /dev/null @@ -1,24 +0,0 @@ - -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - using DotNetCenter.Core.Entities; - using Microsoft.AspNetCore.Identity; - using System; - using System.Collections.Generic; - - public interface IAppUser : AuditableEntity - , TrackableEntity - { - public string Tag { get; } - public string ProfilePictureAddress { get; } - public string FirstName { get; } - public string LastName { get; } - public string Username { get; } - public string Email { get; } - public string DisplayName { get; } - public string AccountType { get; } - public System.DateTime DateRegistered { get; } - public bool TrySetIdentityUser(); - public bool ValidateIdentityUser(); - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppUserClaim.cs b/src/Web/Identity/Core/Source/Common/Models/IAppUserClaim.cs deleted file mode 100644 index 9bb1104..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppUserClaim.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppUserClaim - { - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppUserLogin.cs b/src/Web/Identity/Core/Source/Common/Models/IAppUserLogin.cs deleted file mode 100644 index 5fe756a..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppUserLogin.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppUserLogin - { - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppUserRole.cs b/src/Web/Identity/Core/Source/Common/Models/IAppUserRole.cs deleted file mode 100644 index 9af360a..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppUserRole.cs +++ /dev/null @@ -1,9 +0,0 @@ -using DotNetCenter.Core.Entities; -using System; - -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppUserRole : AuditableEntity - { - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/Common/Models/IAppUserToken.cs b/src/Web/Identity/Core/Source/Common/Models/IAppUserToken.cs deleted file mode 100644 index 0783fb7..0000000 --- a/src/Web/Identity/Core/Source/Common/Models/IAppUserToken.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models -{ - public interface IAppUserToken - { - } -} \ No newline at end of file diff --git a/src/Web/Identity/Core/Source/DotNetCenter.Beyond.Web.Identity.Core.csproj b/src/Web/Identity/Core/Source/DotNetCenter.Beyond.Web.Identity.Core.csproj index 5875c90..7a5218e 100644 --- a/src/Web/Identity/Core/Source/DotNetCenter.Beyond.Web.Identity.Core.csproj +++ b/src/Web/Identity/Core/Source/DotNetCenter.Beyond.Web.Identity.Core.csproj @@ -64,7 +64,6 @@ - @@ -77,4 +76,8 @@ + + + + \ No newline at end of file diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleClaimConfig.cs b/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleClaimConfig.cs deleted file mode 100644 index aa1b593..0000000 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleClaimConfig.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class AppRoleClaimConfig - : IEntityTypeConfiguration - where TEntity : AppRoleClaim - { - public virtual void Configure(EntityTypeBuilder builder) - { - builder.HasKey(o => o.Id); - - builder - .Property(c => c.Id) - .HasDefaultValueSql("NEWID()"); - } - } -} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserConfig.cs b/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserConfig.cs deleted file mode 100644 index 6bb4040..0000000 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserConfig.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - - public abstract class AppUserConfig - : IEntityTypeConfiguration - where TEntity : AppUser - { - public virtual void Configure(EntityTypeBuilder builder) - { - - - builder.Property(c => c.Id) - .HasDefaultValueSql("NEWID()") - .IsRequired(); - - builder - .Property(p => p.DisplayName) - .HasComputedColumnSql("[LastName] + ', ' + [FirstName]"); - - builder - .Property(o => o.DateRegistered) - .IsRequired(); - } - } -} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserRoleConfig.cs b/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserRoleConfig.cs deleted file mode 100644 index dab16ca..0000000 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserRoleConfig.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class AppUserRoleConfig - : IEntityTypeConfiguration - where TEntity : AppUserRole - { - public virtual void Configure(EntityTypeBuilder builder) - { - builder.HasKey(o => o.Id); - - builder - .Property(c => c.Id) - .HasDefaultValueSql("NEWID()"); - } - } -} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.csproj b/src/Web/Identity/Infrastructure/SqlServer/Source/DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.csproj index 7b66dd5..9923b14 100644 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.csproj +++ b/src/Web/Identity/Infrastructure/SqlServer/Source/DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.csproj @@ -73,5 +73,10 @@ + + + + + diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/BasePersistentObject.cs b/src/Web/Identity/ObjRelMapping/Source/Common/BasePersistentObject.cs new file mode 100644 index 0000000..f2dee87 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/BasePersistentObject.cs @@ -0,0 +1,21 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Configuration; +using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +using System; +using System.Collections.Generic; +using System.Text; +using Sys = System; +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common +{ + public abstract class BasePersistentObject : BaseDataAccessObject, PersistableObject + where TAppUser : IIdentityUser + where TKey : struct, IEquatable + { + public override TKey Id { get => base.Id; set => base.Id = value; } + public virtual int? ModifiedBy { get; set; } + public virtual Sys.DateTime? ModifiedDateTime { get; set; } + public virtual int CreatedBy { get; set; } + public virtual Sys.DateTime CreatedDateTime { get; set; } + + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs new file mode 100644 index 0000000..7400153 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs @@ -0,0 +1,28 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Configurations +{ + using Microsoft.EntityFrameworkCore; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using Microsoft.EntityFrameworkCore.Metadata.Builders; + using System; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; + + public abstract class AppRoleClaimConfig + : BaseEntityConfiguration + where TEntity : class, IRoleClaim, new() + { + public AppRoleClaimConfig(string tableName, string schemaName, bool includeAuditColumns = true) + : base(tableName, schemaName, includeAuditColumns) + { + + } + public AppRoleClaimConfig(bool includeAuditColumns = true) + : base(includeAuditColumns) + { + } + public override void Configure(EntityTypeBuilder builder) + { + base.Configure(builder); + } + } +} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs similarity index 85% rename from src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleConfig.cs rename to src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs index c18a562..648b71c 100644 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppRoleConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs @@ -1,7 +1,7 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations -{ +namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model +{ using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; public abstract class AppRoleConfig diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserClaimConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs similarity index 77% rename from src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserClaimConfig.cs rename to src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs index 8f158d3..1280bb2 100644 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserClaimConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs @@ -1,6 +1,5 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models { - using DotNetCenter.Beyond.Web.Identity.Core.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserConfig.cs new file mode 100644 index 0000000..7a9932d --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserConfig.cs @@ -0,0 +1,51 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.EntityFrameworkCore; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using Microsoft.EntityFrameworkCore.Metadata.Builders; + using System; + + public abstract class AppUserConfig + : IEntityTypeConfiguration + where TEntity : AppUser + { + /// + /// Schema must configred in ef apps that use multi context with different schamas, + /// also all configurtins of schemas must configured on all context that used eachother entity + /// + /// + /// + /// + public AppUserConfig(string tableName, string schemaName, bool includeAuditColumns = true) + { + _tableName = tableName; + _schemaName = schemaName; + _includeAuditColumns = includeAuditColumns; + } + public virtual string TableName => _tableName; + private readonly string _tableName; + public virtual string SchemaName => _schemaName; + private readonly string _schemaName; + public virtual bool IncludeAuditColumns => _includeAuditColumns; + private readonly bool _includeAuditColumns; + public virtual void Configure(EntityTypeBuilder builder) + { + if (string.IsNullOrEmpty(SchemaName)) + builder.ToTable(TableName); + else + builder.ToTable(TableName, SchemaName); + + + builder + .Property(o => o.Id) + .UseIdentityColumn(seed: 1, increment: 1) + .ValueGeneratedOnAdd() + .IsRequired(); + + + builder + .Property(p => p.DisplayName) + .HasComputedColumnSql("[LastName] + ', ' + [FirstName]"); + } + } +} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserLoginConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs similarity index 69% rename from src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserLoginConfig.cs rename to src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs index 933f893..bec463d 100644 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserLoginConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs @@ -1,7 +1,7 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models { using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; public abstract class AppUserLoginConfig diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs new file mode 100644 index 0000000..d476198 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs @@ -0,0 +1,27 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.EntityFrameworkCore; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using Microsoft.EntityFrameworkCore.Metadata.Builders; + using System; + using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; + + public abstract class AppUserRoleConfig + : BaseEntityConfiguration + where TEntity : class, IRoleClaim, new() + { + public AppUserRoleConfig(string tableName, string schemaName, bool includeAuditColumns = true) + : base(tableName, schemaName, includeAuditColumns) + { + + } + public AppUserRoleConfig(bool includeAuditColumns = true) + : base(includeAuditColumns) + { + } + public override void Configure(EntityTypeBuilder builder) + { + base.Configure(builder); + } + } +} diff --git a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserTokenConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs similarity index 70% rename from src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserTokenConfig.cs rename to src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs index be7aee0..b54d257 100644 --- a/src/Web/Identity/Infrastructure/SqlServer/Source/Common/Model/Configurations/AppUserTokenConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs @@ -1,7 +1,7 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model.Configurations +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models { using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; public abstract class ApplicationUserTokenConfig diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRole.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRole.cs new file mode 100644 index 0000000..181ff5a --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRole.cs @@ -0,0 +1,26 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.AspNetCore.Identity; + using System; + public class AppRole + : IdentityRole + , IAppRole + { + public AppRole() { } + public AppRole(string name) + => Name = name; + public AppRole(string name, string _description) + { + Name = name; + Description = _description; + } + public string Description { get; set; } + public string Tag { get; set;} + #region Audit + public virtual int? ModifiedBy { get; set; } + public virtual DateTime? ModifiedDateTime { get; set; } + public virtual int CreatedBy { get; set; } + public virtual DateTime CreatedDateTime { get; set; } + #endregion + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRoleClaim.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRoleClaim.cs new file mode 100644 index 0000000..0125e76 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppRoleClaim.cs @@ -0,0 +1,19 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.AspNetCore.Identity; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + public class AppRoleClaim + : IdentityRoleClaim + , IAppRoleClaim + { + public override int Id { get => base.Id; set => base.Id = value; } + public virtual int? ModifiedBy { get; set; } + public virtual DateTime? ModifiedDateTime { get; set; } + public virtual int CreatedBy { get; set; } + public virtual DateTime CreatedDateTime { get; set; } + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUser.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUser.cs new file mode 100644 index 0000000..84084ca --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUser.cs @@ -0,0 +1,15 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.AspNetCore.Identity; + using System; + public class AppUser : IdentityUser, IIdentityUser + { + public override int Id { get => base.Id; set => base.Id = value; } + public string Tag { get; set; } + public string DisplayName { get; set; } + public virtual Guid? ModifiedBy { get; set; } + public virtual DateTime? ModifiedDateTime { get; set; } + public virtual Guid CreatedBy { get; set; } + public virtual DateTime CreatedDateTime { get; set; } + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserClaim.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserClaim.cs new file mode 100644 index 0000000..600528a --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserClaim.cs @@ -0,0 +1,19 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using System; + using Microsoft.AspNetCore.Identity; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + public class AppUserClaim + : IdentityUserClaim + , IAppUserClaim + { + public override int Id { get => base.Id; set => base.Id = value; } + public virtual int? ModifiedBy { get; set; } + public virtual DateTime? ModifiedDateTime { get; set; } + public virtual int CreatedBy { get; set; } + public virtual DateTime CreatedDateTime { get; set; } + } +} diff --git a/src/Web/Identity/Core/Source/Common/Models/AppUserLogin.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserLogin.cs similarity index 54% rename from src/Web/Identity/Core/Source/Common/Models/AppUserLogin.cs rename to src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserLogin.cs index dde99f2..1077695 100644 --- a/src/Web/Identity/Core/Source/Common/Models/AppUserLogin.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserLogin.cs @@ -1,10 +1,10 @@ -namespace DotNetCenter.Beyond.Web.Identity.Core.Models +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models { using Microsoft.AspNetCore.Identity; using System; public class AppUserLogin - : IdentityUserLogin + : IdentityUserLogin , IAppUserLogin { } diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserRole.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserRole.cs new file mode 100644 index 0000000..5d3c240 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserRole.cs @@ -0,0 +1,11 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using Microsoft.AspNetCore.Identity; + using System; + + public class AppUserRole + : IdentityUserRole + , IRoleClaim + { + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs new file mode 100644 index 0000000..2c7b6d2 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs @@ -0,0 +1,11 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model; + using Microsoft.AspNetCore.Identity; + using System; + public class AppUserToken + : IdentityUserToken + , IAppUserToken + { + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRole.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRole.cs new file mode 100644 index 0000000..258c42a --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRole.cs @@ -0,0 +1,13 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using DotNetCenter.Core.Entities; +using System; + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IAppRole: PersistableObject + { + public string Name { get; } + public string Description { get; } + public string Tag { get; } + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRoleClaim.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRoleClaim.cs new file mode 100644 index 0000000..92334e8 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppRoleClaim.cs @@ -0,0 +1,8 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IAppRoleClaim : PersistableObject + { + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserClaim.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserClaim.cs new file mode 100644 index 0000000..4ee45bd --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserClaim.cs @@ -0,0 +1,8 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IAppUserClaim : PersistableObject + { + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserLogin.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserLogin.cs new file mode 100644 index 0000000..08feb80 --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserLogin.cs @@ -0,0 +1,6 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IAppUserLogin + { + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserRole.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserRole.cs new file mode 100644 index 0000000..405307d --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserRole.cs @@ -0,0 +1,11 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; +using DotNetCenter.Core; +using DotNetCenter.Core.Entities; +using System; + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IRoleClaim + { + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserToken.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserToken.cs new file mode 100644 index 0000000..22780cc --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IAppUserToken.cs @@ -0,0 +1,6 @@ +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + public interface IAppUserToken + { + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/IIdentityUser.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IIdentityUser.cs new file mode 100644 index 0000000..57dd3ba --- /dev/null +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/IIdentityUser.cs @@ -0,0 +1,18 @@ + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +{ + using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; + using DotNetCenter.Core.Entities; + using Microsoft.AspNetCore.Identity; + using System; + using System.Collections.Generic; + + public interface IIdentityUser: IAppUser + { + public string Tag { get; } + public string UserName { get; } + public string Email { get; } + public string DisplayName { get; } + //public bool ValidateIdentityUser(); + } +} \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/Auditor.cs b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/Auditor.cs deleted file mode 100644 index 6790d8e..0000000 --- a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/Auditor.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices -{ - using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; - using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Core.Entities; - using DotNetCenter.DateTime.Common; - using Microsoft.EntityFrameworkCore; - using Microsoft.EntityFrameworkCore.ChangeTracking; - using System; - - public class Auditor : Auditable - { - private readonly CurrentUserService _currentUserService; - private readonly CompoundableDateTimeNow _dateTime; - public Auditor(CurrentUserService currentUserService, CompoundableDateTimeNow dateTime) - { - _currentUserService = currentUserService; - _dateTime = dateTime; - } - /// - /// Update Modified Informations to all the Entities in change tracker thats in modified state - /// - /// - public void UpdateModifiedAll(ChangeTracker changeTracker) - { - foreach (var entry in changeTracker.Entries>()) - switch (entry.State) - { - //case EntityState.Added: - // entry.Entity.EntityCreated(_currentUserService.UserId, _dateTime.DateTimeNow); - //break; - case EntityState.Modified: - entry.Entity.RegisterModifiedInformation(_currentUserService.UserId, _dateTime.DateTimeNow); - break; - } - } - } -} diff --git a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs index 8f5a55d..d62650e 100644 --- a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs +++ b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/BaseIdentityDbContext.cs @@ -1,36 +1,98 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices -{ - using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; - using Microsoft.AspNetCore.Identity; - using Microsoft.EntityFrameworkCore; - using System; - using System.Threading; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Identity.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.Core.Models; - - public abstract class BaseIdentityDbContext - - : IdentityDbContext - where TContext : IdentityDbContext - where TAppUser : AppUser - where TAppRole : AppRole - where TAppUserClaim : AppUserClaim - where TUserRole : AppUserRole - where TUserLogin : AppUserLogin - where TRoleClaim : AppRoleClaim - where TUserToken : AppUserToken - , new() +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices +//{ +// using DotNetCenter.Beyond.Web.Identity.Core; +// using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; +// using Microsoft.AspNetCore.Identity; +// using Microsoft.EntityFrameworkCore; +// using System; +// using System.Threading; +// using System.Threading.Tasks; +// using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + +// public abstract class BaseIdentityDbContext +// +// : IdentityDbContext +// where TContext : IdentityDbContext +// where TAppUser : AppUser +// where TAppRole : AppRole +// where TAppUserClaim : AppUserClaim +// where TUserRole : AppUserRole +// where TUserLogin : AppUserLogin +// where TRoleClaim : AppRoleClaim +// where TUserToken : AppUserToken +// , new() +// { +// public BaseIdentityDbContext() { } +// public BaseIdentityDbContext(DbContextOptions options, Auditable auditor) +// : base(options) => _auditor = auditor; + +// private readonly Auditable _auditor; +// public void Audit() => _auditor.UpdateModifiedAll(ChangeTracker); + +// public abstract void Save(); +// public abstract Task SaveAsync(CancellationToken cancellationToken); +// } +//} + +using DotNetCenter.Beyond.Web.Identity.Core; +using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +using System.Reflection; + +namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices +{ + public abstract class BaseIndetityDbContext + : IdentityDbContext + , IdentityDbService + where TAppUser : IdentityUser, IIdentityUser, new() + where TAppRole : IdentityRole, IAppRole, new() + where TIdentityDbContext : BaseIndetityDbContext { - public BaseIdentityDbContext() { } - public BaseIdentityDbContext(DbContextOptions options, Auditable auditor) - : base(options) => _auditor = auditor; + + public BaseIndetityDbContext() { } + public BaseIndetityDbContext(DbContextOptions options, Auditable auditor) + : base(options) => _auditor = auditor; + + public virtual string Schema { get; } + public abstract Assembly ConfigurationAssemby { get; } + public abstract bool UseAssemblyToScanConfigurations { get; } + public abstract bool EnableSensitiveDataLogging { get; } private readonly Auditable _auditor; - public void Audit() => _auditor.UpdateModifiedAll(ChangeTracker); + public virtual void Audit() => _auditor.UpdateModifiedAll(ChangeTracker); + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); - public abstract void Save(); - public abstract Task SaveAsync(CancellationToken cancellationToken); + optionsBuilder.EnableSensitiveDataLogging(UseAssemblyToScanConfigurations); } + public void Save() + => SaveChanges(); + + + public async Task SaveAsync(CancellationToken cancellationToken) + => await SaveChangesAsync(cancellationToken); + public async Task SaveAsync() + => await SaveChangesAsync(new CancellationToken(false)); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + if (!string.IsNullOrEmpty(Schema) && !string.IsNullOrWhiteSpace(Schema)) + builder.HasDefaultSchema(Schema); + else + builder.HasDefaultSchema("IDS"); + + + if (UseAssemblyToScanConfigurations) + builder.ApplyConfigurationsFromAssembly(ConfigurationAssemby); + } +} } diff --git a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/IdentityDbService.cs b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/IdentityDbService.cs index bf8e4f0..5049dd6 100644 --- a/src/Web/Identity/ObjRelMapping/Source/DbContextServices/IdentityDbService.cs +++ b/src/Web/Identity/ObjRelMapping/Source/DbContextServices/IdentityDbService.cs @@ -5,9 +5,10 @@ namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices using System; using System.Threading; using System.Threading.Tasks; - public interface IdentityDbService : IDisposable, IAsyncDisposable, AuditableDbContext, EntryableDbContext, SetableDbContext + public interface IdentityDbService : DbService { void Save(); + Task SaveAsync(); Task SaveAsync(CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/Web/Identity/ObjRelMapping/Source/DependencyResolution/AuditorDIC.cs b/src/Web/Identity/ObjRelMapping/Source/DependencyResolution/AuditorDIC.cs deleted file mode 100644 index 362de75..0000000 --- a/src/Web/Identity/ObjRelMapping/Source/DependencyResolution/AuditorDIC.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DependencyResolution -{ - using Microsoft.Extensions.DependencyInjection; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices; - using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; - public static class AuditorDIC - { - public static IServiceCollection AddAuditor(this IServiceCollection services) - { - services.AddTransient(); - return services; - } - } -} diff --git a/src/Web/Identity/ObjRelMapping/Source/DotNetCenter.Beyond.Web.Identity.ObjRelMapping.csproj b/src/Web/Identity/ObjRelMapping/Source/DotNetCenter.Beyond.Web.Identity.ObjRelMapping.csproj index 9b11505..8195d2f 100644 --- a/src/Web/Identity/ObjRelMapping/Source/DotNetCenter.Beyond.Web.Identity.ObjRelMapping.csproj +++ b/src/Web/Identity/ObjRelMapping/Source/DotNetCenter.Beyond.Web.Identity.ObjRelMapping.csproj @@ -68,14 +68,21 @@ + - + + + + + + + diff --git a/src/Web/Identity/Services/Source/Auditor.cs b/src/Web/Identity/Services/Source/Auditor.cs new file mode 100644 index 0000000..46e05d8 --- /dev/null +++ b/src/Web/Identity/Services/Source/Auditor.cs @@ -0,0 +1,59 @@ +namespace DotNetCenter.Beyond.Web.Identity.Services.DbContextServices +{ + using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; + using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; + using DotNetCenter.Beyond.Web.Identity.Core; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; + using DotNetCenter.Core.Entities; + using DotNetCenter.DateTime.Common; + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.ChangeTracking; + using System; + + public class Auditor: Auditable + { + private readonly CurrentUserService _currentUserService; + private readonly CompoundableDateTimeNow _dateTime; + public Auditor(CurrentUserService currentUserService, CompoundableDateTimeNow dateTime) + { + _currentUserService = currentUserService; + _dateTime = dateTime; + } + /// + /// Update Modified Informations to all the Entities in change tracker thats in modified state + /// + /// + public virtual void UpdateModifiedAll(ChangeTracker changeTracker) + { + foreach (var entry in changeTracker.Entries>()) + switch (entry.State) + { + //case EntityState.Added: + // entry.Entity.EntityCreated(_currentUserService.UserId, _dateTime.DateTimeNow); + //break; + case EntityState.Modified: + entry.Entity.ModifiedBy = _currentUserService.UserId; + entry.Entity.ModifiedDateTime = _dateTime.DateTimeNow; + break; + } + } + /// + /// Update Modified Informations to all the Entities in change tracker thats in modified state + /// + /// + public virtual void UpdateCreatorAll(ChangeTracker changeTracker) + { + foreach (var entry in changeTracker.Entries>()) + switch (entry.State) + { + //case EntityState.Added: + // entry.Entity.EntityCreated(_currentUserService.UserId, _dateTime.DateTimeNow); + //break; + case EntityState.Modified: + entry.Entity.CreatedBy = _currentUserService.UserId ?? throw new NullReferenceException(); + entry.Entity.CreatedDateTime = _dateTime.DateTimeNow; + break; + } + } + } +} diff --git a/src/Web/Identity/Services/Source/BaseCurrentUserService.cs b/src/Web/Identity/Services/Source/BaseCurrentUserService.cs index 0b5fbc0..758ff70 100644 --- a/src/Web/Identity/Services/Source/BaseCurrentUserService.cs +++ b/src/Web/Identity/Services/Source/BaseCurrentUserService.cs @@ -2,9 +2,11 @@ { using System; using System.Security.Claims; + using System.Threading; + using System.Threading.Tasks; using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Beyond.Web.Identity.Core.Managers; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; using Microsoft.AspNetCore.Http; public abstract class BaseCurrentUserService @@ -20,30 +22,33 @@ public abstract class BaseCurrentUserService public BaseCurrentUserService(IHttpContextAccessor httpContextAccessor) => HttpContextAccessor = httpContextAccessor; public abstract TAppUser TryGetUser(out TAppUser user); - public bool TrySetUsername() - { - var userName = HttpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name); - if (string.IsNullOrEmpty(userName) || string.IsNullOrWhiteSpace(userName)) - return false; + //public bool TrySetUsername() + //{ + // var userName = HttpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name); + // if (string.IsNullOrEmpty(userName) || string.IsNullOrWhiteSpace(userName)) + // return false; - Username = userName; - return true; - } - public bool TrySetUserId() - { - var id = HttpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier); - var isParsed = Guid.TryParse(id, out var userId); - UserId = Guid.Empty; - if (!isParsed) - return false; + // Username = userName; + // return true; + //} + //public bool TrySetUserId() + //{ + // var id = HttpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier); + // var isParsed = Guid.TryParse(id, out var userId); + // UserId = Guid.Empty; + // if (!isParsed) + // return false; - UserId = userId; - return true; - } - public Guid UserId { get; protected set; } + // UserId = userId; + // return true; + //} + public int? UserId { get; protected set; } public string Username { get; protected set; } - public bool IsUserAuthenticated { get => HttpContextAccessor.HttpContext.User.Identity.IsAuthenticated;} + public bool IsUserAuthenticated() + => HttpContextAccessor.HttpContext.User.Identity.IsAuthenticated; + public abstract Task IsUserAuthenticated(CancellationToken cancellationToken); + public IHttpContextAccessor HttpContextAccessor { get; } - + } } diff --git a/src/Web/Identity/Services/Source/BaseIdentityService.cs b/src/Web/Identity/Services/Source/BaseIdentityService.cs index 36d3264..6324848 100644 --- a/src/Web/Identity/Services/Source/BaseIdentityService.cs +++ b/src/Web/Identity/Services/Source/BaseIdentityService.cs @@ -1,71 +1,65 @@ namespace DotNetCenter.Beyond.Web.Identity.Services { + using DotNetCenter.Beyond.ObjRelMapping.Core.Infrastructure.Common; using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Beyond.Web.Identity.Core.Managers; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; using DotNetCenter.Core.ErrorHandlers; using Microsoft.EntityFrameworkCore; using System; using System.Threading.Tasks; - public abstract class BaseIdentityService : IdentityService + public abstract class BaseIdentityService: IdentityService + where TUserManagerService : UserManagerService + where TCurrentUserService : CurrentUserService + where TAppUser : IIdentityUser { - protected readonly UserManagerService _userManager; - protected readonly CurrentUserService _currentUserService; - public BaseIdentityService(UserManagerService userManager, - CurrentUserService currentUserService) + protected readonly TUserManagerService _userManager; + protected readonly TCurrentUserService _currentUserService; + public BaseIdentityService(TUserManagerService userManager, + TCurrentUserService currentUserService) { _userManager = userManager; _currentUserService = currentUserService; } - public virtual async Task GetUsernameAsync(Guid userId) + public virtual async Task GetUsernameAsync(int userId) { - if (!_currentUserService.IsUserAuthenticated) + if (!_currentUserService.IsUserAuthenticated()) return ""; var user = await _userManager.Users.FirstOrDefaultAsync(o => o.Id == userId); - return user.Username; + return user.UserName; } - public virtual async Task DeleteUserAsync(IAppUser user) + public virtual async Task DeleteUserAsync(TAppUser user) { var result = await _userManager.DeleteAsync(user); return result.ToApplicationResult(); } - public virtual async Task DeleteUserAsync(Guid userId) + public virtual async Task DeleteUserAsync(int userId) { - IAppUser user = await GetUserFormUserManagerAsync(userId); + TAppUser user = await GetUserFormUserManagerAsync(userId); var result = await _userManager.DeleteAsync(user); return result.ToApplicationResult(); } - private async Task GetUserFormUserManagerAsync(Guid userId) + private async Task GetUserFormUserManagerAsync(int? userId) { - return await _userManager.Users.FirstAsync(o => o.Id.CompareTo(userId) == 0); + return await _userManager.Users?.FirstAsync(o => o.Id == userId); } public virtual async Task DeleteCurrentUserAsync() { - if (!_currentUserService.IsUserAuthenticated) + if (!_currentUserService.IsUserAuthenticated()) return new ResultContainer(false, new[] { "" }); var user = await GetUserFormUserManagerAsync(_currentUserService.UserId); var result = await _userManager.DeleteAsync(user); return result.ToApplicationResult(); } - public async Task<(ResultContainer Result, Guid UserId)> CreateUserAsync(string userName, string password) - { - var user = new AppUser(Guid.NewGuid(), DateTime.UtcNow) - { - UserName = userName, - }; - - var result = await _userManager.CreateAsync(user); - - return (result.ToApplicationResult(), user.Id); - } + public abstract Task<(ResultContainer Result, int UserId)> CreateUserAsync(TAppUser user); } } diff --git a/src/Web/Identity/Services/Source/CurrentUserService.cs b/src/Web/Identity/Services/Source/CurrentUserService.cs new file mode 100644 index 0000000..7fc661f --- /dev/null +++ b/src/Web/Identity/Services/Source/CurrentUserService.cs @@ -0,0 +1,14 @@ +namespace DotNetCenter.Beyond.Web.Identity.Services.Managers +{ + using System; + using System.Threading; + using System.Threading.Tasks; + + public interface CurrentUserService + { + int? UserId { get; } + string Username { get; } + public bool IsUserAuthenticated(); + public Task IsUserAuthenticated(CancellationToken cancellationToken); + } +} diff --git a/src/Web/Identity/Services/Source/DependencyResolution/AuditorDIC.cs b/src/Web/Identity/Services/Source/DependencyResolution/AuditorDIC.cs new file mode 100644 index 0000000..2b405b1 --- /dev/null +++ b/src/Web/Identity/Services/Source/DependencyResolution/AuditorDIC.cs @@ -0,0 +1,20 @@ +using DotNetCenter.Beyond.ObjRelMapping.Core.Auditing; +using DotNetCenter.Beyond.Web.Identity.Services.DbContextServices; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DotNetCenter.Beyond.Web.Identity.Services.DependencyResolution +{ + public static class AuditorDIC + { + public static IServiceCollection AddAuditor(this IServiceCollection services) + { + services.AddSingleton(); + return services; + } + } +} diff --git a/src/Web/Identity/ObjRelMapping/Source/DependencyResolution/IdentityDbServicesDIC.cs b/src/Web/Identity/Services/Source/DependencyResolution/IdentityDbServicesDIC.cs similarity index 64% rename from src/Web/Identity/ObjRelMapping/Source/DependencyResolution/IdentityDbServicesDIC.cs rename to src/Web/Identity/Services/Source/DependencyResolution/IdentityDbServicesDIC.cs index 33b10cd..366b1f8 100644 --- a/src/Web/Identity/ObjRelMapping/Source/DependencyResolution/IdentityDbServicesDIC.cs +++ b/src/Web/Identity/Services/Source/DependencyResolution/IdentityDbServicesDIC.cs @@ -1,15 +1,16 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DependencyResolution +namespace DotNetCenter.Beyond.Web.Identity.Services.DependencyResolution { + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices; using Microsoft.Extensions.DependencyInjection; public static class IdentityDbServicesDIC { - public static IServiceCollection AddIdentityDbServices(this IServiceCollection services) - where TServiceDbContext : IdentityDbService + public static IServiceCollection AddIdentityDbServices(this IServiceCollection services) where TImplementationDbContext : class, IdentityDbService { services.AddTransient(); + services.AddTransient(); services.AddAuditor(); return services; } diff --git a/src/Web/Identity/Services/Source/DependencyResolution/IdentityServicesDIC.cs b/src/Web/Identity/Services/Source/DependencyResolution/IdentityServicesDIC.cs deleted file mode 100644 index 997f320..0000000 --- a/src/Web/Identity/Services/Source/DependencyResolution/IdentityServicesDIC.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace DotNetCenter.Beyond.Web.Identity.Services.DependencyResolution -{ - using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Beyond.Web.Identity.Services; - using Microsoft.AspNetCore.Mvc.RazorPages; - using Microsoft.Extensions.DependencyInjection; - using System; - - public static class IdentityServicesDIC - { - public static IServiceCollection AddIdentityServices(this IServiceCollection services) - { - return services; - } - } -} diff --git a/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs b/src/Web/Identity/Services/Source/DependencyResolution/ManagerServicesDIC.cs similarity index 64% rename from src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs rename to src/Web/Identity/Services/Source/DependencyResolution/ManagerServicesDIC.cs index ea3ceb6..87c0490 100644 --- a/src/Web/Identity/Core/Source/DependencyResolution/ManagerServicesDIC.cs +++ b/src/Web/Identity/Services/Source/DependencyResolution/ManagerServicesDIC.cs @@ -1,20 +1,15 @@ -using DotNetCenter.Beyond.Web.Identity.Core.Managers; -using DotNetCenter.Beyond.Web.Identity.Core.Models; +using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +using DotNetCenter.Beyond.Web.Identity.Services.Managers; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace DotNetCenter.Beyond.Web.Identity.Core.DependencyResolution +namespace DotNetCenter.Beyond.Web.Identity.Services.DependencyResolution { public static class ManagerServicesDIC { public static IServiceCollection AddManagerServices(this IServiceCollection services) where TUserManager : class, UserManagerService where TSignInManager : class, SignInManagerService - where TAppUser : AppUser + where TAppUser : IIdentityUser { services.AddSingleton, TUserManager>(); services.AddSingleton, TSignInManager>(); diff --git a/src/Web/Identity/Services/Source/DotNetCenter.Beyond.Web.Identity.Services.csproj b/src/Web/Identity/Services/Source/DotNetCenter.Beyond.Web.Identity.Services.csproj index 5afd865..469d576 100644 --- a/src/Web/Identity/Services/Source/DotNetCenter.Beyond.Web.Identity.Services.csproj +++ b/src/Web/Identity/Services/Source/DotNetCenter.Beyond.Web.Identity.Services.csproj @@ -63,6 +63,7 @@ + diff --git a/src/Web/Identity/Services/Source/IdentityService.cs b/src/Web/Identity/Services/Source/IdentityService.cs new file mode 100644 index 0000000..c34c09a --- /dev/null +++ b/src/Web/Identity/Services/Source/IdentityService.cs @@ -0,0 +1,14 @@ +namespace DotNetCenter.Beyond.Web.Identity.Services +{ + using System; + using System.Threading.Tasks; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Core.ErrorHandlers; + public interface IdentityService + where TAppUser : IIdentityUser + { + Task GetUsernameAsync(int userId); + Task<(ResultContainer Result, int UserId)> CreateUserAsync(TAppUser user); + Task DeleteUserAsync(int userId); + } +} diff --git a/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs b/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs index 764bccd..570b6ef 100644 --- a/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs +++ b/src/Web/Identity/Services/Source/Managers/BaseAppSignInManager.cs @@ -1,7 +1,6 @@ namespace DotNetCenter.Beyond.Web.Identity.Services.Managers { - using DotNetCenter.Beyond.Web.Identity.Core.Managers; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; diff --git a/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs b/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs index a5a9152..f67a6e5 100644 --- a/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs +++ b/src/Web/Identity/Services/Source/Managers/BaseAppUserManager.cs @@ -10,10 +10,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - using DotNetCenter.Beyond.Web.Identity.Core.Models; using DotNetCenter.Beyond.Web.Identity.Core; using DotNetCenter.Core.ErrorHandlers; - using DotNetCenter.Beyond.Web.Identity.Core.Managers; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; public abstract class BaseAppUserManager : UserManager, UserManagerService diff --git a/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs b/src/Web/Identity/Services/Source/Managers/SignInManagerService.cs similarity index 77% rename from src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs rename to src/Web/Identity/Services/Source/Managers/SignInManagerService.cs index d6ddeac..2d503f1 100644 --- a/src/Web/Identity/Core/Source/Common/Managers/SignInManagerService.cs +++ b/src/Web/Identity/Services/Source/Managers/SignInManagerService.cs @@ -1,12 +1,12 @@ -using DotNetCenter.Beyond.Web.Identity.Core.Models; +using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using System; using System.Security.Claims; using System.Threading.Tasks; -namespace DotNetCenter.Beyond.Web.Identity.Core.Managers +namespace DotNetCenter.Beyond.Web.Identity.Services.Managers { public interface SignInManagerService - where TAppUser : IAppUser + where TAppUser : IIdentityUser { #region IsSignedIn // diff --git a/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs b/src/Web/Identity/Services/Source/Managers/UserManagerService.cs similarity index 89% rename from src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs rename to src/Web/Identity/Services/Source/Managers/UserManagerService.cs index 9461f42..6039139 100644 --- a/src/Web/Identity/Core/Source/Common/Managers/UserManagerService.cs +++ b/src/Web/Identity/Services/Source/Managers/UserManagerService.cs @@ -1,16 +1,16 @@ -using DotNetCenter.Beyond.Web.Identity.Core.Models; +using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using Microsoft.AspNetCore.Identity; using System; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -namespace DotNetCenter.Beyond.Web.Identity.Core.Managers +namespace DotNetCenter.Beyond.Web.Identity.Services.Managers { - public interface UserManagerService : UserManagerService + public interface UserManagerService : UserManagerService { } public interface UserManagerService - where TAppUser : IAppUser + where TAppUser : IIdentityUser { #region CreateAsync public Task CreateAsync(TAppUser user); diff --git a/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs b/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs index 04e8560..8c24e9b 100644 --- a/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs +++ b/src/Web/Identity/Services/Source/RevalidatingIdentityAuthenticationStateProvider.cs @@ -1,7 +1,7 @@ namespace DotNetCenter.Beyond.Web.Identity.Services { - using DotNetCenter.Beyond.Web.Identity.Core.Managers; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Server; using Microsoft.AspNetCore.Identity; @@ -24,7 +24,7 @@ public class RevalidatingIdentityAuthenticationStateProvider private readonly IServiceScopeFactory _scopeFactory; private readonly IdentityOptions _options; public RevalidatingIdentityAuthenticationStateProvider(ILoggerFactory loggerFactory, - UserManagerService userManagerService, + UserManagerService userManagerService, IServiceScopeFactory scopeFactory, IOptions optionsAccessor) : base(loggerFactory) @@ -34,7 +34,7 @@ public RevalidatingIdentityAuthenticationStateProvider(ILoggerFactory loggerFact _options = optionsAccessor.Value; } - private readonly UserManagerService _userManager; + private readonly UserManagerService _userManager; protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30); protected override async Task ValidateAuthenticationStateAsync(AuthenticationState authenticationState, CancellationToken cancellationToken) diff --git a/src/Web/Identity/Services/Source/UserAuthenticationService.cs b/src/Web/Identity/Services/Source/UserAuthenticationService.cs index a52f1bd..4bc4ec4 100644 --- a/src/Web/Identity/Services/Source/UserAuthenticationService.cs +++ b/src/Web/Identity/Services/Source/UserAuthenticationService.cs @@ -1,9 +1,9 @@ namespace DotNetCenter.Beyond.Web.Identity.Services { using DotNetCenter.Beyond.Web.Identity.Core; - using DotNetCenter.Beyond.Web.Identity.Core.Managers; - using DotNetCenter.Beyond.Web.Identity.Core.Models; + using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.DbContextServices; + using DotNetCenter.Beyond.Web.Identity.Services.Managers; using DotNetCenter.Core.ExceptionHandlers; using Microsoft.AspNetCore.Identity; using Microsoft.IdentityModel.Tokens; @@ -17,18 +17,18 @@ public abstract class UserAuthenticationService : UserAuthenticable { private readonly IdentityDbService _context; private readonly CurrentUserService _currentUserService; - private readonly UserManagerService _userManager; - private readonly SignInManagerService _signInManager; + private readonly UserManagerService _userManager; + private readonly SignInManagerService _signInManager; - public IdentityService IdentityService => _identityService; - private readonly IdentityService _identityService; + public IdentityService IdentityService => _identityService; + private readonly IdentityService _identityService; public UserAuthenticationService( IdentityDbService context, - IdentityService identityService, + IdentityService identityService, CurrentUserService currentUserService, //#??must confugured for dep inj - UserManagerService userManager, - SignInManagerService signInManager) + UserManagerService userManager, + SignInManagerService signInManager) { _context = context; _identityService = identityService; @@ -37,42 +37,42 @@ public UserAuthenticationService( _currentUserService = currentUserService; } - public string GenerateJwtForCurrentUser( + public abstract string GenerateJwtForCurrentUser( string symmetricKey, string jwtAudience, string jwtIssuer, - double expirationFromNow) - { + double expirationFromNow); + //{ - if (!_currentUserService.TrySetUserId()) - throw new NotFoundException("IdentityUser UserId not found!"); + // if (!_currentUserService.TrySetUserId()) + // throw new NotFoundException("IdentityUser UserId not found!"); - if (!_currentUserService.TrySetUsername()) - throw new NotFoundException("IdentityUser Username not found!"); + // if (!_currentUserService.TrySetUsername()) + // throw new NotFoundException("IdentityUser Username not found!"); - var claims = new List - { - new Claim(Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames.Sub, _currentUserService.Username), - new Claim(Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), - new Claim(ClaimTypes.NameIdentifier, _currentUserService.UserId.ToString()) - }; - var key = new SymmetricSecurityKey( - Encoding.UTF8.GetBytes(symmetricKey)); + // var claims = new List + //{ + // new Claim(Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames.Sub, _currentUserService.Username), + // new Claim(Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), + // new Claim(ClaimTypes.NameIdentifier, _currentUserService.UserId.ToString()) + //}; + // var key = new SymmetricSecurityKey( + // Encoding.UTF8.GetBytes(symmetricKey)); - var creds = new SigningCredentials( - key, SecurityAlgorithms.HmacSha256); + // var creds = new SigningCredentials( + // key, SecurityAlgorithms.HmacSha256); - var expires = DateTime.Now.AddDays(expirationFromNow); + // var expires = DateTime.Now.AddDays(expirationFromNow); - var token = new JwtSecurityToken( - jwtIssuer, - jwtAudience, - claims, - expires: expires, - signingCredentials: creds - ); - return new JwtSecurityTokenHandler().WriteToken(token); - } + // var token = new JwtSecurityToken( + // jwtIssuer, + // jwtAudience, + // claims, + // expires: expires, + // signingCredentials: creds + // ); + // return new JwtSecurityTokenHandler().WriteToken(token); + //} public bool isUserAthenticated(ClaimsPrincipal claimsPrincipal) => _signInManager.IsSignedIn(claimsPrincipal); From 93e548ef0306682d59482c90987f439f389eb485 Mon Sep 17 00:00:00 2001 From: Arsalan Fallahpour Date: Thu, 2 Sep 2021 07:14:11 -0700 Subject: [PATCH 4/5] Version 0.2.12 --- src/Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0beec4a..50f552c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -18,9 +18,9 @@ latest https://github.com/arsalanfallahpour/DotNetCenter.Beyond.git - 0.2.11 - 0.2.11 - 0.2.11 + 0.2.12 + 0.2.12 + 0.2.12 3.3.2 3.9.0-2.final From dce1fa816b682364c592005cabb85873ae8d5e69 Mon Sep 17 00:00:00 2001 From: Arsalan Fallahpour Date: Thu, 2 Sep 2021 09:23:11 -0700 Subject: [PATCH 5/5] Release 0.2.12 Stable With DotNetCenter.Core 0.2.7 --- src/Directory.Build.props | 2 +- .../Configurations/AppRoleClaimConfig.cs | 58 ++++++++++--------- .../Common/Configurations/AppRoleConfig.cs | 38 ++++++------ .../Configurations/AppUserClaimConfig.cs | 36 ++++++------ .../Configurations/AppUserLoginConfig.cs | 26 ++++----- .../Configurations/AppUserRoleConfig.cs | 50 ++++++++-------- .../Configurations/AppUserTokenConfig.cs | 30 +++++----- .../Source/Common/Models/AppUserToken.cs | 1 - 8 files changed, 123 insertions(+), 118 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 50f552c..f0b0f7c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -79,7 +79,7 @@ 0.2.1 - 0.2.6 + 0.2.7 0.2.2 8.1.1 diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs index 7400153..e429072 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleClaimConfig.cs @@ -1,28 +1,34 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Configurations -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Configurations +//{ +// using Microsoft.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; +// using DotNetCenter.Core; - public abstract class AppRoleClaimConfig - : BaseEntityConfiguration - where TEntity : class, IRoleClaim, new() - { - public AppRoleClaimConfig(string tableName, string schemaName, bool includeAuditColumns = true) - : base(tableName, schemaName, includeAuditColumns) - { +// public abstract class AppRoleClaimConfig +// : BaseEntityConfiguration +// where TEntity : class, IRoleClaim, Entity, new() +// { +// public AppRoleClaimConfig(bool configureKey = true) +// :base(configureKey) +// { - } - public AppRoleClaimConfig(bool includeAuditColumns = true) - : base(includeAuditColumns) - { - } - public override void Configure(EntityTypeBuilder builder) - { - base.Configure(builder); - } - } -} +// } +// public AppRoleClaimConfig(string tableName, string schemaName, bool includeAuditColumns = true) +// : base(tableName, schemaName, includeAuditColumns) +// { + +// } +// public AppRoleClaimConfig(bool configureKey = true) +// : base(configureKey) +// { +// } +// public override void Configure(EntityTypeBuilder builder) +// { +// base.Configure(builder); +// } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs index 648b71c..a60b757 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppRoleConfig.cs @@ -1,20 +1,20 @@ -namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class AppRoleConfig - : IEntityTypeConfiguration - where TEntity : AppRole - { - public virtual void Configure(EntityTypeBuilder builder) - { - builder.HasKey(o => o.Id); +//namespace DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model +//{ +// using Microsoft.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// public abstract class AppRoleConfig +// : IEntityTypeConfiguration +// where TEntity : AppRole +// { +// public virtual void Configure(EntityTypeBuilder builder) +// { +// builder.HasKey(o => o.Id); - builder - .Property(c => c.Id) - .HasDefaultValueSql("NEWID()"); - } - } -} +// builder +// .Property(c => c.Id) +// .HasDefaultValueSql("NEWID()"); +// } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs index 1280bb2..7e1dda9 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserClaimConfig.cs @@ -1,19 +1,19 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models -{ - using Microsoft.EntityFrameworkCore; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class AppUserClaimConfig - : IEntityTypeConfiguration where TEntity - : AppUserClaim - { - public virtual void Configure(EntityTypeBuilder builder) - { - builder.HasKey(o => o.Id); +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +//{ +// using Microsoft.EntityFrameworkCore; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// public abstract class AppUserClaimConfig +// : IEntityTypeConfiguration where TEntity +// : AppUserClaim +// { +// public virtual void Configure(EntityTypeBuilder builder) +// { +// builder.HasKey(o => o.Id); - builder - .Property(c => c.Id) - .HasDefaultValueSql("NEWID()"); - } - } -} +// builder +// .Property(c => c.Id) +// .HasDefaultValueSql("NEWID()"); +// } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs index bec463d..5ba551c 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserLoginConfig.cs @@ -1,13 +1,13 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class AppUserLoginConfig - : IEntityTypeConfiguration - where TEntity : AppUserLogin - { - public virtual void Configure(EntityTypeBuilder builder) { } - } -} +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +//{ +// using Microsoft.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// public abstract class AppUserLoginConfig +// : IEntityTypeConfiguration +// where TEntity : AppUserLogin +// { +// public virtual void Configure(EntityTypeBuilder builder) { } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs index d476198..a42797d 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserRoleConfig.cs @@ -1,27 +1,27 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +//{ +// using Microsoft.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// using DotNetCenter.Beyond.ObjRelMapping.Infrastructure.Configuration; - public abstract class AppUserRoleConfig - : BaseEntityConfiguration - where TEntity : class, IRoleClaim, new() - { - public AppUserRoleConfig(string tableName, string schemaName, bool includeAuditColumns = true) - : base(tableName, schemaName, includeAuditColumns) - { +// public abstract class AppUserRoleConfig +// : BaseEntityConfiguration +// where TEntity : class, IRoleClaim, new() +// { +// public AppUserRoleConfig(string tableName, string schemaName, bool includeAuditColumns = true) +// : base(tableName, schemaName, includeAuditColumns) +// { - } - public AppUserRoleConfig(bool includeAuditColumns = true) - : base(includeAuditColumns) - { - } - public override void Configure(EntityTypeBuilder builder) - { - base.Configure(builder); - } - } -} +// } +// public AppUserRoleConfig(bool includeAuditColumns = true) +// : base(includeAuditColumns) +// { +// } +// public override void Configure(EntityTypeBuilder builder) +// { +// base.Configure(builder); +// } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs index b54d257..d61f631 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Configurations/AppUserTokenConfig.cs @@ -1,15 +1,15 @@ -namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models -{ - using Microsoft.EntityFrameworkCore; - using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; - using Microsoft.EntityFrameworkCore.Metadata.Builders; - using System; - public abstract class ApplicationUserTokenConfig - : IEntityTypeConfiguration - where TEntity : AppUserToken - { - public virtual void Configure(EntityTypeBuilder builder) - { - } - } -} +//namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models +//{ +// using Microsoft.EntityFrameworkCore; +// using DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models; +// using Microsoft.EntityFrameworkCore.Metadata.Builders; +// using System; +// public abstract class ApplicationUserTokenConfig +// : IEntityTypeConfiguration +// where TEntity : AppUserToken +// { +// public virtual void Configure(EntityTypeBuilder builder) +// { +// } +// } +//} diff --git a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs index 2c7b6d2..6b50c0f 100644 --- a/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs +++ b/src/Web/Identity/ObjRelMapping/Source/Common/Models/AppUserToken.cs @@ -1,6 +1,5 @@ namespace DotNetCenter.Beyond.Web.Identity.ObjRelMapping.Common.Models { - using DotNetCenter.Beyond.Web.Identity.Infrastructure.SqlServer.Common.Model; using Microsoft.AspNetCore.Identity; using System; public class AppUserToken