From 0daa339d12660be49b6f77b3db7725251b9532e1 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 18 Aug 2026 14:05:36 +0330 Subject: [PATCH] adding Data Requirement on XContent Service ... --- .../Entities/XContentEntityConfiguration.cs | 17 ++ Constants/XContentServiceConstants.cs | 4 + DI/XDIHelperExtensions.cs | 237 +++++++++++++++ Helpers/XContentServiceHelper.cs | 282 ++++++++++++++++++ Interfaces/Dtos/IXContentDtoHub.cs | 10 + Interfaces/Dtos/IXContentRepositoryService.cs | 10 + Interfaces/Dtos/IXContentServiceProvider.cs | 11 + Interfaces/Enrichers/IXContentEnricher.cs | 6 + Interfaces/Entities/IXContentEntityHub.cs | 9 + .../Entities/IXContentGraphQLTypeHelper.cs | 9 + Interfaces/Entities/IXContentKeyGenerator.cs | 9 + Interfaces/Entities/IXContentRepository.cs | 9 + .../Entities/IXContentRepositoryEvents.cs | 8 + .../Entities/IXContentRepositoryProvider.cs | 10 + Interfaces/Entities/IXContentSeeder.cs | 9 + Models/Dtos/XContentDto.cs | 19 +- Models/Entities/XContent.cs | 2 + Providers/Dtos/XContentDtoHub.cs | 17 ++ Providers/Dtos/XContentRepositoryService.cs | 26 ++ Providers/Dtos/XContentServiceProvider.cs | 27 ++ Providers/Enrichers/XContentEnricher.cs | 10 + Providers/Entities/XContentEFRepository.cs | 27 ++ Providers/Entities/XContentEntityHub.cs | 16 + .../Entities/XContentInMemoryRepository.cs | 22 ++ Providers/Entities/XContentKeyGenerator.cs | 9 + Providers/Entities/XContentMongoRepository.cs | 26 ++ .../Entities/XContentRepositoryEvents.cs | 9 + .../Entities/XContentRepositoryProvider.cs | 26 ++ Providers/Entities/XContentSeederBase.cs | 24 ++ .../GraphQL/XContentGraphQLTypeHelper.cs | 21 ++ Providers/GraphQL/XContentGraphQuery.cs | 23 ++ Providers/GraphQL/XContentGraphSchema.cs | 13 + Providers/GraphQL/XContentGraphType.cs | 18 ++ Providers/XContentEntityRegisterar.cs | 35 +++ 34 files changed, 1009 insertions(+), 1 deletion(-) create mode 100644 Configuration/Entities/XContentEntityConfiguration.cs create mode 100644 DI/XDIHelperExtensions.cs create mode 100644 Helpers/XContentServiceHelper.cs create mode 100644 Interfaces/Dtos/IXContentDtoHub.cs create mode 100644 Interfaces/Dtos/IXContentRepositoryService.cs create mode 100644 Interfaces/Dtos/IXContentServiceProvider.cs create mode 100644 Interfaces/Enrichers/IXContentEnricher.cs create mode 100644 Interfaces/Entities/IXContentEntityHub.cs create mode 100644 Interfaces/Entities/IXContentGraphQLTypeHelper.cs create mode 100644 Interfaces/Entities/IXContentKeyGenerator.cs create mode 100644 Interfaces/Entities/IXContentRepository.cs create mode 100644 Interfaces/Entities/IXContentRepositoryEvents.cs create mode 100644 Interfaces/Entities/IXContentRepositoryProvider.cs create mode 100644 Interfaces/Entities/IXContentSeeder.cs create mode 100644 Providers/Dtos/XContentDtoHub.cs create mode 100644 Providers/Dtos/XContentRepositoryService.cs create mode 100644 Providers/Dtos/XContentServiceProvider.cs create mode 100644 Providers/Enrichers/XContentEnricher.cs create mode 100644 Providers/Entities/XContentEFRepository.cs create mode 100644 Providers/Entities/XContentEntityHub.cs create mode 100644 Providers/Entities/XContentInMemoryRepository.cs create mode 100644 Providers/Entities/XContentKeyGenerator.cs create mode 100644 Providers/Entities/XContentMongoRepository.cs create mode 100644 Providers/Entities/XContentRepositoryEvents.cs create mode 100644 Providers/Entities/XContentRepositoryProvider.cs create mode 100644 Providers/Entities/XContentSeederBase.cs create mode 100644 Providers/GraphQL/XContentGraphQLTypeHelper.cs create mode 100644 Providers/GraphQL/XContentGraphQuery.cs create mode 100644 Providers/GraphQL/XContentGraphSchema.cs create mode 100644 Providers/GraphQL/XContentGraphType.cs create mode 100644 Providers/XContentEntityRegisterar.cs diff --git a/Configuration/Entities/XContentEntityConfiguration.cs b/Configuration/Entities/XContentEntityConfiguration.cs new file mode 100644 index 0000000..d830382 --- /dev/null +++ b/Configuration/Entities/XContentEntityConfiguration.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using xContentService.Constants; +using xContentService.Models.Entities; +using xDataService.Providers; + +namespace xContentService.Configuration.Entities +{ + public class XContentEntityConfiguration : XBaseEntityTypeConfiguration + { + public override void Configure(EntityTypeBuilder builder) + { + builder.ToTable(XContentServiceConstants.XContentTable); + } + } +} \ No newline at end of file diff --git a/Constants/XContentServiceConstants.cs b/Constants/XContentServiceConstants.cs index f0d5831..9e08908 100644 --- a/Constants/XContentServiceConstants.cs +++ b/Constants/XContentServiceConstants.cs @@ -19,5 +19,9 @@ namespace xContentService.Constants // Hubs ... public const string XContentDtoHub = "contentDto"; public const string XContentEntityHub = "contentEntity"; + + // + // EF Repositories Helper Extensions ... + public const string GetXContentEFRepositoryDescriptor = "GetXContentEFRepositoryDescriptor"; } } \ No newline at end of file diff --git a/DI/XDIHelperExtensions.cs b/DI/XDIHelperExtensions.cs new file mode 100644 index 0000000..02f48a2 --- /dev/null +++ b/DI/XDIHelperExtensions.cs @@ -0,0 +1,237 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using xCommons.Extensions; +using xContentService.Constants; +using xContentService.Providers.Dtos; +using xContentService.Providers.Entities; +using xDataService.Constants; +using xDataService.Models; +using xPushService.DI; +using xDataService.DI; +using xPushService.Helpers; +using System; +using xExceptions.Constants; +using xContentService.Helpers; +using xCommons.Helpers; +using xContentService.Interfaces.Dtos; +using xContentService.Interfaces.Entities; +using xDataService.Db; + +namespace xContentService.DI +{ + /// + /// Service Registration Extensions Classes ... + /// + public static partial class XDIHelperExtensions + { + /// + /// Register Service ... + /// + /// + /// + /// + public static void AddXContentService( + this IServiceCollection services, + XRepositoryType repositoryType, + ServiceLifetime lifeTime = ServiceLifetime.Scoped + ) + { + AddContentService( + contextType: null, + services: services, + lifeTime: lifeTime, + repositoryType: repositoryType + ); + } + + /// + /// Register Service ... + /// + /// + /// + /// + /// + public static void AddXContentService( + this IServiceCollection services, + XRepositoryType repositoryType, + ServiceLifetime lifeTime = ServiceLifetime.Scoped + ) + where TContext : XDbContext + { + AddContentService( + services: services, + lifeTime: lifeTime, + contextType: typeof(TContext), + repositoryType: repositoryType + ); + } + + /// + /// Use xContentService Middleware ... + /// + /// + /// + public static void UseXContentService( + this IApplicationBuilder app, + bool isDevelopmentEnvironment = false + ) + { + // + #region Using XContent Hubs ... + // + var pushHelper = new XPushServiceHelper(); + + // + pushHelper.AddHub(XContentServiceConstants.XContentDtoHub); + pushHelper.AddHub(XContentServiceConstants.XContentEntityHub); + + // + app.UseXPushService(pushHelper); + #endregion + + // + // Using XContent Repository Descriptor ... + if (!descriptor.IsNull()) + { + // + app.UseXRepository( + descriptor: descriptor, + isDevelopmentEnvironment: isDevelopmentEnvironment + ); + } + } + + // + #region Private ... + private static XRepositoryDescriptor descriptor = null; + + /// + /// a LogTag for Service ... + /// + private static string XLogTag = XContentServiceConstants.XContentServiceDILogTag; + + /// + /// print a log in Console ... + /// + /// + private static void Log(string message) + { + Console.WriteLine($"{XLogTag} => {message}"); + } + + /// + /// Register Service ... + /// + /// + /// + /// + /// + private static void AddContentService( + IServiceCollection services, + XRepositoryType repositoryType, + Type contextType = null, + ServiceLifetime lifeTime = ServiceLifetime.Scoped + ) + { + // + var exception = XException.InvalidArgs.ToException(); ; + + // + // Services ... + var isServicesExists = !services.IsNull(); + if (!isServicesExists) + { + // + Log("Service Registration failed, services not provided ..."); + throw exception; + } + + // + // Lifetime ... + var isLifetimeExists = !lifeTime.IsNull(); + if (!isLifetimeExists) + { + // + Log("Service Registration failed, lifetime not provided ..."); + throw exception; + } + + // + // Validate Repository Type ... + var isRepositoryTypeValid = + (repositoryType == XRepositoryType.EF && + !contextType.IsNull()) || + ((repositoryType == XRepositoryType.Mongo || + repositoryType == XRepositoryType.InMemory) && + contextType.IsNull()); + if (!isRepositoryTypeValid) + { + // + Log("Service Registration failed, Invalid Repository Type and Context Type ..."); + throw exception; + } + + // + // Maske Instance of Repository Descriptor + // Based on Provided Type ... + switch (repositoryType) + { + // + case XRepositoryType.EF: + // + descriptor = typeof(XContentServiceHelper) + .InvokeGenericMethod( + args: null, + runtimeType: contextType, + methodName: XContentServiceConstants.GetXContentEFRepositoryDescriptor + ); + break; + + // + case XRepositoryType.Mongo: + descriptor = XContentServiceHelper.GetXContentMongoRepositoryDescriptor(); + break; + + // + case XRepositoryType.InMemory: + descriptor = XContentServiceHelper.GetXContentInMemoryRepositoryDescriptor(); + break; + } + + // + // Register XContent Repository Descriptor ... + services.AddXRepository( + lifeTime: lifeTime, + descriptor: descriptor + ); + + // + // Register Dto Services ... + services.Add( + new ServiceDescriptor(typeof(IXContentServiceProvider), typeof(XContentServiceProvider), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXContentRepositoryService), typeof(XContentRepositoryService), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXContentRepositoryProvider), typeof(XContentRepositoryProvider), lifeTime) + ); + + // + // Register Additional Service ... + // services.Add( + // new ServiceDescriptor(typeof(IXContentTagProvider), typeof(XContentTagProvider), lifeTime) + // ); + // services.Add( + // new ServiceDescriptor(typeof(IXContentTagProvided), typeof(XContentTagProvided), lifeTime) + // ); + // services.Add( + // new ServiceDescriptor(typeof(IXContentProvider), typeof(XContentProvider), lifeTime) + // ); + + // + Log("Service Regitration Succeed ..."); + } + #endregion + } +} \ No newline at end of file diff --git a/Helpers/XContentServiceHelper.cs b/Helpers/XContentServiceHelper.cs new file mode 100644 index 0000000..39a19c0 --- /dev/null +++ b/Helpers/XContentServiceHelper.cs @@ -0,0 +1,282 @@ +using System; +using GraphQL.Types; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xContentService.Providers.Entities; +using xContentService.Providers.GraphQL; +using xDataService.Db; +using xDataService.Models; +using xDataService.Providers; + +namespace xContentService.Helpers +{ + public static class XContentServiceHelper + { + // + #region XContent ... + // + #region EF Repository Descriptor Provider(s) ... + public static XEFRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentEFRepository, + TContext + > GetXContentEFRepositoryDescriptor() + where TContext : XDbContext + { + // + var result = new XEFRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentEFRepository, + TContext + >(); + + // + return result; + } + + public static XEFRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentEFRepository, + TContext, + IXContentSeeder, + TSeederImplementation + > GetXContentEFRepositoryDescriptor() + where TContext : XDbContext + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XEFRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentEFRepository, + TContext, + IXContentSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region Mongo Repository Descriptor Provider(s) ... + public static XMongoRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentMongoRepository + > GetXContentMongoRepositoryDescriptor() + { + // + var result = new XMongoRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentMongoRepository + >(); + + // + return result; + } + + public static XMongoRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentMongoRepository, + IXContentSeeder, + TSeederImplementation + > GetXContentMongoRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XMongoRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentMongoRepository, + IXContentSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region InMemory Repository Descriptor Provider(s) ... + public static XInMemoryRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentInMemoryRepository + > GetXContentInMemoryRepositoryDescriptor() + { + // + var result = new XInMemoryRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentInMemoryRepository + >(); + + // + return result; + } + + public static XInMemoryRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentInMemoryRepository, + IXContentSeeder, + TSeederImplementation + > GetXContentInMemoryRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XInMemoryRepositoryDescriptor< + XContent, + Guid, + IXContentKeyGenerator, + XContentKeyGenerator, + IXContentRepositoryEvents, + XContentRepositoryEvents, + XContentGraphType, + GuidGraphType, + XContentGraphQuery, + IXContentGraphQLTypeHelper, + XContentGraphQLTypeHelper, + XContentGraphSchema, + IXContentRepository, + XContentInMemoryRepository, + IXContentSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + #endregion + } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXContentDtoHub.cs b/Interfaces/Dtos/IXContentDtoHub.cs new file mode 100644 index 0000000..2886f0e --- /dev/null +++ b/Interfaces/Dtos/IXContentDtoHub.cs @@ -0,0 +1,10 @@ +using System; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xPushService.Interfaces; + +namespace xContentService.Interfaces.Dtos +{ + public interface IXContentDtoHub : IXBaseDtoHub + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXContentRepositoryService.cs b/Interfaces/Dtos/IXContentRepositoryService.cs new file mode 100644 index 0000000..9525c69 --- /dev/null +++ b/Interfaces/Dtos/IXContentRepositoryService.cs @@ -0,0 +1,10 @@ +using System; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Dtos +{ + public interface IXContentRepositoryService : IXBaseRepositoryService + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXContentServiceProvider.cs b/Interfaces/Dtos/IXContentServiceProvider.cs new file mode 100644 index 0000000..e349266 --- /dev/null +++ b/Interfaces/Dtos/IXContentServiceProvider.cs @@ -0,0 +1,11 @@ +using System; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xContentService.Providers.Dtos; +using xPushService.Interfaces; + +namespace xContentService.Interfaces.Dtos +{ + public interface IXContentServiceProvider : IXBaseDtoProvider + { } +} \ No newline at end of file diff --git a/Interfaces/Enrichers/IXContentEnricher.cs b/Interfaces/Enrichers/IXContentEnricher.cs new file mode 100644 index 0000000..e614e0e --- /dev/null +++ b/Interfaces/Enrichers/IXContentEnricher.cs @@ -0,0 +1,6 @@ +namespace xContentService.Interfaces.Enrichers +{ + // TODO: Complete this ... + public interface IXContentEnricher + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentEntityHub.cs b/Interfaces/Entities/IXContentEntityHub.cs new file mode 100644 index 0000000..fee5aa0 --- /dev/null +++ b/Interfaces/Entities/IXContentEntityHub.cs @@ -0,0 +1,9 @@ +using System; +using xContentService.Models.Entities; +using xPushService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentEntityHub : IXBaseEntityHub + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentGraphQLTypeHelper.cs b/Interfaces/Entities/IXContentGraphQLTypeHelper.cs new file mode 100644 index 0000000..e6389a9 --- /dev/null +++ b/Interfaces/Entities/IXContentGraphQLTypeHelper.cs @@ -0,0 +1,9 @@ +using System; +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentGraphQLTypeHelper : IXBaseGraphQLTypeHelper + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentKeyGenerator.cs b/Interfaces/Entities/IXContentKeyGenerator.cs new file mode 100644 index 0000000..cb457c5 --- /dev/null +++ b/Interfaces/Entities/IXContentKeyGenerator.cs @@ -0,0 +1,9 @@ +using System; +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentKeyGenerator : IXKeyGenerator + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentRepository.cs b/Interfaces/Entities/IXContentRepository.cs new file mode 100644 index 0000000..7e0882d --- /dev/null +++ b/Interfaces/Entities/IXContentRepository.cs @@ -0,0 +1,9 @@ +using System; +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentRepository : IXBaseRepository + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentRepositoryEvents.cs b/Interfaces/Entities/IXContentRepositoryEvents.cs new file mode 100644 index 0000000..d4c1ac0 --- /dev/null +++ b/Interfaces/Entities/IXContentRepositoryEvents.cs @@ -0,0 +1,8 @@ +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentRepositoryEvents : IXBaseRepositoryEvents + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentRepositoryProvider.cs b/Interfaces/Entities/IXContentRepositoryProvider.cs new file mode 100644 index 0000000..09477da --- /dev/null +++ b/Interfaces/Entities/IXContentRepositoryProvider.cs @@ -0,0 +1,10 @@ +using System; +using xContentService.Models.Entities; +using xContentService.Providers.Entities; +using xPushService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentRepositoryProvider : IXBaseEntityProvider + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXContentSeeder.cs b/Interfaces/Entities/IXContentSeeder.cs new file mode 100644 index 0000000..2436270 --- /dev/null +++ b/Interfaces/Entities/IXContentSeeder.cs @@ -0,0 +1,9 @@ +using System; +using xContentService.Models.Entities; +using xDataService.Interfaces; + +namespace xContentService.Interfaces.Entities +{ + public interface IXContentSeeder : IXBaseDbSeeder + { } +} \ No newline at end of file diff --git a/Models/Dtos/XContentDto.cs b/Models/Dtos/XContentDto.cs index 74fdc89..a25c5ea 100644 --- a/Models/Dtos/XContentDto.cs +++ b/Models/Dtos/XContentDto.cs @@ -1,7 +1,24 @@ +using System; +using xModels.Base; +using xModels.Dtos; + namespace xContentService.Models.Dtos { - public class XContentDto + /// + /// Content Describe DTO ... + /// + public class XContentDto : XBaseGuidIDEntityDto { + public string OwnerId { get; set; } + public virtual XPersonDto Owner { get; set; } + public string Title { get; set; } + public virtual XResourceDto TitleResource { get; set; } + + public string Description { get; set; } + public virtual XResourceDto DescriptionResource { get; set; } + + public DateTime CreatedOn { get; set; } + public DateTime UpdatedAt { get; set; } } } \ No newline at end of file diff --git a/Models/Entities/XContent.cs b/Models/Entities/XContent.cs index c8a5640..52cf9b4 100644 --- a/Models/Entities/XContent.cs +++ b/Models/Entities/XContent.cs @@ -1,3 +1,5 @@ +using System; +using System.ComponentModel.DataAnnotations; using xModels.Base; namespace xContentService.Models.Entities diff --git a/Providers/Dtos/XContentDtoHub.cs b/Providers/Dtos/XContentDtoHub.cs new file mode 100644 index 0000000..87e3720 --- /dev/null +++ b/Providers/Dtos/XContentDtoHub.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Extensions.Logging; +using xContentService.Interfaces.Dtos; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xPushService.Base; + +namespace xContentService.Providers.Dtos +{ + public class XContentDtoHub : XBaseDtoHub, IXContentDtoHub + { + public XContentDtoHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XContentRepositoryService.cs b/Providers/Dtos/XContentRepositoryService.cs new file mode 100644 index 0000000..0968b73 --- /dev/null +++ b/Providers/Dtos/XContentRepositoryService.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using AutoMapper; +using xContentService.Interfaces.Dtos; +using xContentService.Interfaces.Entities; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xDataService.Providers; + +namespace xContentService.Providers.Dtos +{ + public class XContentRepositoryService : XBaseRepositoryService, IXContentRepositoryService + { + public XContentRepositoryService( + IXContentRepository repository, + IEnumerable mapperProfiles = null + ) : base( + repository, + mapperProfiles + ) + { } + + // + // TODO: Implement Enrichers ... + } +} \ No newline at end of file diff --git a/Providers/Dtos/XContentServiceProvider.cs b/Providers/Dtos/XContentServiceProvider.cs new file mode 100644 index 0000000..2227f4c --- /dev/null +++ b/Providers/Dtos/XContentServiceProvider.cs @@ -0,0 +1,27 @@ +using System; +using Microsoft.AspNetCore.SignalR; +using xContentService.Interfaces.Dtos; +using xContentService.Models.Dtos; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; + +namespace xContentService.Providers.Dtos +{ + public class XContentServiceProvider : XBaseDtoProvider, IXContentServiceProvider + { + public XContentServiceProvider( + IHubContext hub, + XDataServiceConfiguration dataConfiguration, + IXContentRepositoryService service, + IXIdentityProvider identityProvider = null + ) : base( + hub, + dataConfiguration, + service, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Enrichers/XContentEnricher.cs b/Providers/Enrichers/XContentEnricher.cs new file mode 100644 index 0000000..32731f8 --- /dev/null +++ b/Providers/Enrichers/XContentEnricher.cs @@ -0,0 +1,10 @@ +using xContentService.Interfaces.Enrichers; + +namespace xContentService.Providers.Enrichers +{ + public class XContentEnricher : IXContentEnricher + { + // + // TODO: Complete this ... + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentEFRepository.cs b/Providers/Entities/XContentEFRepository.cs new file mode 100644 index 0000000..035912f --- /dev/null +++ b/Providers/Entities/XContentEFRepository.cs @@ -0,0 +1,27 @@ +using System; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xDataService.Db; +using xDataService.Interfaces; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public class XContentEFRepository : XBaseEFRepository, IXContentRepository + where TContext : XDbContext + { + public XContentEFRepository( + IXUnitOfWorks unitOfWorks, + XDataServiceConfiguration configuration, + IXContentKeyGenerator keyGenerator = null, + IXContentRepositoryEvents baseRepositoryEvents = null + ) : base( + unitOfWorks, + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentEntityHub.cs b/Providers/Entities/XContentEntityHub.cs new file mode 100644 index 0000000..c98516c --- /dev/null +++ b/Providers/Entities/XContentEntityHub.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Extensions.Logging; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xPushService.Base; + +namespace xContentService.Providers.Entities +{ + public class XContentEntityHub : XBaseEntityHub, IXContentEntityHub + { + public XContentEntityHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentInMemoryRepository.cs b/Providers/Entities/XContentInMemoryRepository.cs new file mode 100644 index 0000000..e05c2af --- /dev/null +++ b/Providers/Entities/XContentInMemoryRepository.cs @@ -0,0 +1,22 @@ +using System; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public class XContentInMemoryRepository : XBaseInMemoryRepository, IXContentRepository + { + public XContentInMemoryRepository( + XDataServiceConfiguration configuration, + IXContentKeyGenerator keyGenerator = null, + IXContentRepositoryEvents baseRepositoryEvents = null + ) : base( + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentKeyGenerator.cs b/Providers/Entities/XContentKeyGenerator.cs new file mode 100644 index 0000000..66aedb1 --- /dev/null +++ b/Providers/Entities/XContentKeyGenerator.cs @@ -0,0 +1,9 @@ +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public class XContentKeyGenerator : XGuidKeyGenerator, IXContentKeyGenerator + { } +} \ No newline at end of file diff --git a/Providers/Entities/XContentMongoRepository.cs b/Providers/Entities/XContentMongoRepository.cs new file mode 100644 index 0000000..f2c21c7 --- /dev/null +++ b/Providers/Entities/XContentMongoRepository.cs @@ -0,0 +1,26 @@ +using System; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public class XContentMongoRepository : XBaseMongoRepository, IXContentRepository + { + public XContentMongoRepository( + XDataBaseConfiguration dbConfiguration, + XDataServiceConfiguration configuration, + string collectionName = null, + IXContentKeyGenerator keyGenerator = null, + IXContentRepositoryEvents baseRepositoryEvents = null + ) : base( + dbConfiguration, + configuration, + collectionName, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentRepositoryEvents.cs b/Providers/Entities/XContentRepositoryEvents.cs new file mode 100644 index 0000000..099e8ac --- /dev/null +++ b/Providers/Entities/XContentRepositoryEvents.cs @@ -0,0 +1,9 @@ +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public class XContentRepositoryEvents : XBaseRepositoryEvents, IXContentRepositoryEvents + { } +} \ No newline at end of file diff --git a/Providers/Entities/XContentRepositoryProvider.cs b/Providers/Entities/XContentRepositoryProvider.cs new file mode 100644 index 0000000..1ac7966 --- /dev/null +++ b/Providers/Entities/XContentRepositoryProvider.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.AspNetCore.SignalR; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; + +namespace xContentService.Providers.Entities +{ + public class XContentRepositoryProvider : XBaseEntityProvider, IXContentRepositoryProvider + { + public XContentRepositoryProvider( + IHubContext hub, + IXContentRepository repository, + XDataServiceConfiguration dataConfiguration, + IXIdentityProvider identityProvider = null + ) : base( + hub, + repository, + dataConfiguration, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XContentSeederBase.cs b/Providers/Entities/XContentSeederBase.cs new file mode 100644 index 0000000..ee5012d --- /dev/null +++ b/Providers/Entities/XContentSeederBase.cs @@ -0,0 +1,24 @@ +using System; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xDataService.Providers; + +namespace xContentService.Providers.Entities +{ + public abstract class XContentSeederBase : XBaseDbSeeder, IXContentSeeder + { + protected XContentSeederBase( + string entity, + string database, + IXContentRepository repository, + XDataServiceConfiguration dataServiceConfiguration + ) : base( + entity, + database, + repository, + dataServiceConfiguration + ) + { } + } +} \ No newline at end of file diff --git a/Providers/GraphQL/XContentGraphQLTypeHelper.cs b/Providers/GraphQL/XContentGraphQLTypeHelper.cs new file mode 100644 index 0000000..a3d98b4 --- /dev/null +++ b/Providers/GraphQL/XContentGraphQLTypeHelper.cs @@ -0,0 +1,21 @@ +using System; +using xContentService.Constants; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.GraphQL; + +namespace xContentService.Providers.GraphQL +{ + public class XContentGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXContentGraphQLTypeHelper + { + public override string GetInQueryCollectionName() + { + return XContentServiceConstants.XContentCollectionName; + } + + public override string GetInQuerySingleName() + { + return XContentServiceConstants.XContentSingleName; + } + } +} \ No newline at end of file diff --git a/Providers/GraphQL/XContentGraphQuery.cs b/Providers/GraphQL/XContentGraphQuery.cs new file mode 100644 index 0000000..a99624f --- /dev/null +++ b/Providers/GraphQL/XContentGraphQuery.cs @@ -0,0 +1,23 @@ +using System; +using GraphQL.Types; +using xContentService.Interfaces.Entities; +using xContentService.Models.Entities; +using xDataService.Configuration; +using xDataService.GraphQL; + +namespace xContentService.Providers.GraphQL +{ + public class XContentGraphQuery : XBaseGraphQLQuery + { + public XContentGraphQuery( + XDataServiceConfiguration configuration, + IXContentRepository repository, + IXContentGraphQLTypeHelper helper + ) : base( + configuration, + repository, + helper + ) + { } + } +} \ No newline at end of file diff --git a/Providers/GraphQL/XContentGraphSchema.cs b/Providers/GraphQL/XContentGraphSchema.cs new file mode 100644 index 0000000..1539dec --- /dev/null +++ b/Providers/GraphQL/XContentGraphSchema.cs @@ -0,0 +1,13 @@ +using System; +using GraphQL.Types; + +namespace xContentService.Providers.GraphQL +{ + public class XContentGraphSchema : Schema + { + public XContentGraphSchema(IServiceProvider services) : base(services) + { + Query = (XContentGraphQuery)services.GetService(typeof(XContentGraphQuery)); + } + } +} \ No newline at end of file diff --git a/Providers/GraphQL/XContentGraphType.cs b/Providers/GraphQL/XContentGraphType.cs new file mode 100644 index 0000000..76c9097 --- /dev/null +++ b/Providers/GraphQL/XContentGraphType.cs @@ -0,0 +1,18 @@ +using System; +using xContentService.Models.Entities; +using xDataService.GraphQL; + +namespace xContentService.Providers.GraphQL +{ + public class XContentGraphType : XBaseGraphObjectType + { + public XContentGraphType() : base() + { + Field(x => x.Title); + Field(x => x.OwnerId); + Field(x => x.CreatedOn); + Field(x => x.UpdatedAt); + Field(x => x.Description); + } + } +} \ No newline at end of file diff --git a/Providers/XContentEntityRegisterar.cs b/Providers/XContentEntityRegisterar.cs new file mode 100644 index 0000000..caa546b --- /dev/null +++ b/Providers/XContentEntityRegisterar.cs @@ -0,0 +1,35 @@ +using System; +using Microsoft.EntityFrameworkCore; +using xContentService.Configuration.Entities; +using xContentService.Models.Entities; +using xDataService.Interfaces; +using xDataService.Providers; + +namespace xContentService.Providers +{ + public class XContentEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar + { + public XContentEntityRegisterar() + : base(nameof(XContentEntityRegisterar)) + { + // + // Add Entity ... + AddEntity(); + } + + /// + /// Configure Entities ... + /// + /// + public override void ConfigureEntities(ModelBuilder modelBuilder) + { + // + // Configure Entity Using Provided ... + modelBuilder + .ApplyConfigurationsFromAssembly(typeof(XContentEntityConfiguration).Assembly); + + // + base.ConfigureEntities(modelBuilder); + } + } +} \ No newline at end of file