add support for Db Seeder, Fix GraphQL Generic Usage ...
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using xDataService.Constants;
|
using xDataService.Constants;
|
||||||
|
|
||||||
namespace xDataService.Configuration
|
namespace xDataService.Configuration
|
||||||
@@ -18,5 +19,11 @@ namespace xDataService.Configuration
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public string ConnectionString { get; set; }
|
public string ConnectionString { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holds Seeding items ...
|
||||||
|
/// nameof(TEntity) => TEntity
|
||||||
|
/// </summary>
|
||||||
|
public IDictionary<string, List<dynamic>> SeedItems { get; set; } = new Dictionary<string, List<dynamic>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ namespace xDataService.Configuration
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="XDataBaseConfiguration"></typeparam>
|
/// <typeparam name="XDataBaseConfiguration"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Dictionary<string, XDataBaseConfiguration> Databases { get; set; } = new Dictionary<string, XDataBaseConfiguration>();
|
public IDictionary<string, XDataBaseConfiguration> Databases { get; set; } = new Dictionary<string, XDataBaseConfiguration>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable Soft Delete Entities or Not ...
|
/// Enable Soft Delete Entities or Not ...
|
||||||
@@ -27,6 +27,11 @@ namespace xDataService.Configuration
|
|||||||
/// <value></value>
|
/// <value></value>
|
||||||
public bool EnableSoftDelete { get; set; }
|
public bool EnableSoftDelete { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Seeding Mode ...
|
||||||
|
/// </summary>
|
||||||
|
public XDbSeedingMode SeedingMode { get; set; } = XDbSeedingMode.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable Tracking of Entities ...
|
/// Enable Tracking of Entities ...
|
||||||
/// Only Used on EFCore ...
|
/// Only Used on EFCore ...
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
namespace xDataService.Constants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All Seeding Data Mode ...
|
||||||
|
/// </summary>
|
||||||
|
public enum XDbSeedingMode
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// No Seed Data ...
|
||||||
|
/// </summary>
|
||||||
|
None,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seed Only New Items ...
|
||||||
|
/// </summary>
|
||||||
|
AddIfNotExists,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seed Force (Add/Update) ...
|
||||||
|
/// </summary>
|
||||||
|
AddOrUpdate,
|
||||||
|
}
|
||||||
|
}
|
||||||
+78
-82
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -11,7 +11,6 @@ using xDataService.Configuration;
|
|||||||
using xDataService.Constants;
|
using xDataService.Constants;
|
||||||
using xDataService.Extensions;
|
using xDataService.Extensions;
|
||||||
using xDataService.Helpers;
|
using xDataService.Helpers;
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.Models;
|
using xDataService.Models;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
|
|
||||||
@@ -34,6 +33,25 @@ namespace xDataService.DI
|
|||||||
.GetSection(ConfigurationNodeNames.DATA_SERVICE_NODE);
|
.GetSection(ConfigurationNodeNames.DATA_SERVICE_NODE);
|
||||||
var result = xDataServiceConfigSection.Get<XDataServiceConfiguration>();
|
var result = xDataServiceConfigSection.Get<XDataServiceConfiguration>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading Seeders ...
|
||||||
|
if (!result.IsNull() &&
|
||||||
|
result.Databases.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result
|
||||||
|
.Databases
|
||||||
|
.ToList()
|
||||||
|
.ForEach(db =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Fix this ...
|
||||||
|
var sectionName = $"{ConfigurationNodeNames.DATA_SERVICE_NODE}:{nameof(XDataServiceConfiguration.Databases)}:{db.Key}:{nameof(XDataBaseConfiguration.SeedItems)}";
|
||||||
|
// var seedItems = source.GetSectionAsDictionary(sectionName);
|
||||||
|
// db.Value.SeedItems = seedItems;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -229,7 +247,8 @@ namespace xDataService.DI
|
|||||||
|
|
||||||
public static void UseXDatabase(
|
public static void UseXDatabase(
|
||||||
this IApplicationBuilder source,
|
this IApplicationBuilder source,
|
||||||
XDatabaseDescriptor descriptor
|
XDatabaseDescriptor descriptor,
|
||||||
|
bool isDevelopmentEnvironment = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -244,6 +263,14 @@ namespace xDataService.DI
|
|||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var withPlayground = false;
|
||||||
|
if (isDevelopmentEnvironment)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
withPlayground = true;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check Repositories Exists ...
|
// Check Repositories Exists ...
|
||||||
isValid = descriptor.HasRepositories();
|
isValid = descriptor.HasRepositories();
|
||||||
@@ -265,61 +292,66 @@ namespace xDataService.DI
|
|||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(r =>
|
.ForEach(r =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
Log($"Start Using Repository of: {r.Entity}");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Seeder Exists ...
|
||||||
|
isValid = r.HasSeeder();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var seeder = (dynamic)scope.ServiceProvider.GetService(r.SeederService);
|
||||||
|
isValid = seeder != null;
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Log($"Start Seeding {r.Entity} ...");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Seeding ...
|
||||||
|
seeder
|
||||||
|
.Seed()
|
||||||
|
.RunTask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check GraphQL Support ...
|
// Check GraphQL Support ...
|
||||||
isValid = r.HasGraphSupport();
|
isValid = r.HasGraphSupport();
|
||||||
if (isValid)
|
if (isValid)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Inject GraphQL Type Helper ...
|
// Use WebSockets ...
|
||||||
var helper = scope.ServiceProvider.GetService(r.GraphTypeHelperService);
|
source.UseWebSockets();
|
||||||
isValid = !helper.IsNullOrDefault();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Log($"unable to find GraphQLTypeHelper for Entiy: {r.Entity}");
|
|
||||||
XException.NotFound.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var methods = source.GetType().GetMethods();
|
// Inject GraphQL Type Helper ...
|
||||||
isValid =
|
var helper = (dynamic)scope.ServiceProvider.GetService(r.GraphTypeHelperService);
|
||||||
!methods.IsNull() &&
|
isValid = helper != null;
|
||||||
methods.HasChild();
|
|
||||||
if (isValid)
|
if (isValid)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
try
|
string graphPath = helper.GetGraphQLPath();
|
||||||
{
|
typeof(XDataServiceHelper).InvokeGenericMethod(
|
||||||
//
|
methodName: "UseXGraphQL",
|
||||||
// UseGraphQL ...
|
runtimeTypes: [
|
||||||
var method = methods.First(m =>
|
r.Entity,
|
||||||
m.IsGenericMethod &&
|
r.Key,
|
||||||
m.Name == "UseGraphQL" &&
|
r.GraphType,
|
||||||
m.GetGenericArguments().Length == 1 &&
|
r.GraphTypeKey,
|
||||||
m.GetParameters().Length == 1
|
r.GraphQuery,
|
||||||
|
r.GraphTypeHelperService,
|
||||||
|
r.GraphTypeHelperImplementation,
|
||||||
|
r.GraphSchema
|
||||||
|
],
|
||||||
|
args: [
|
||||||
|
source,
|
||||||
|
graphPath,
|
||||||
|
withPlayground,
|
||||||
|
null
|
||||||
|
]
|
||||||
);
|
);
|
||||||
var genericMethod = method.MakeGenericMethod(r.GraphSchema);
|
|
||||||
genericMethod.Invoke(null, ((dynamic)helper).GetGraphQLPath());
|
|
||||||
|
|
||||||
//
|
|
||||||
// UseGraphQLWebSockets ...
|
|
||||||
method = methods.First(m =>
|
|
||||||
m.IsGenericMethod &&
|
|
||||||
m.Name == "UseGraphQLWebSockets" &&
|
|
||||||
m.GetGenericArguments().Length == 1 &&
|
|
||||||
m.GetParameters().Length == 0
|
|
||||||
);
|
|
||||||
genericMethod = method.MakeGenericMethod(r.GraphSchema);
|
|
||||||
genericMethod.Invoke(null, null);
|
|
||||||
|
|
||||||
//
|
|
||||||
Log($"Register GraphQL Middleware for Entity {r.Entity} Successfully ...");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log($"Registration GraphQL Middleware for Entity {r.Entity} failed due {ex.Message} ...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -343,42 +375,6 @@ namespace xDataService.DI
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"{XLogTag} => {message}");
|
Console.WriteLine($"{XLogTag} => {message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Do Seeding Initialization Data on DbContext
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app"></param>
|
|
||||||
private static void SeedData(
|
|
||||||
this IApplicationBuilder app
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
using (var scope = app.ApplicationServices.CreateScope())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var dbSeeder = scope.ServiceProvider.GetService<IXDbSeeder>();
|
|
||||||
Console.WriteLine($"XDataService: dbSeeder retrieved from DI is => {!dbSeeder.IsNull()}");
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!dbSeeder.IsNull())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
dbSeeder.Seed()
|
|
||||||
.GetAwaiter()
|
|
||||||
.GetResult();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Console.WriteLine(" ");
|
|
||||||
Console.WriteLine($"XDataService: Seeding Error: {ex.Message}");
|
|
||||||
XException.InvalidConfiguration.Throw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xDataService.Db;
|
||||||
|
using xDataService.EFRepositories;
|
||||||
|
using xDataService.Events;
|
||||||
|
using xDataService.InMemRepositories;
|
||||||
|
using xDataService.Interfaces;
|
||||||
using xDataService.Models;
|
using xDataService.Models;
|
||||||
|
using xDataService.MongoRepositories;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xModels.Base;
|
||||||
|
|
||||||
namespace xDataService.Extensions
|
namespace xDataService.Extensions
|
||||||
{
|
{
|
||||||
public static class XRepositoryDescriptorExtensions
|
public static class XRepositoryDescriptorExtensions
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
#region Hasers ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validate a Descriptor ...
|
/// Validate a Descriptor ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,6 +74,7 @@ namespace xDataService.Extensions
|
|||||||
//
|
//
|
||||||
var result =
|
var result =
|
||||||
source.IsValid() &&
|
source.IsValid() &&
|
||||||
|
source.HasRepository() &&
|
||||||
!source.GraphType.IsNull() &&
|
!source.GraphType.IsNull() &&
|
||||||
!source.GraphQuery.IsNull() &&
|
!source.GraphQuery.IsNull() &&
|
||||||
!source.GraphSchema.IsNull() &&
|
!source.GraphSchema.IsNull() &&
|
||||||
@@ -108,5 +119,185 @@ namespace xDataService.Extensions
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check a Descriptor Has Seeder or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool HasSeeder(this XRepositoryDescriptor source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
source.IsValid() &&
|
||||||
|
source.HasRepository() &&
|
||||||
|
!source.SeederService.IsNull() &&
|
||||||
|
!source.SeederImplementation.IsNull();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Builders ...
|
||||||
|
public static XRepositoryDescriptor AddEntity<TEntity, TKey>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.Key = typeof(TKey);
|
||||||
|
source.Entity = typeof(TEntity);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddEvents<TEntity, TKey, TEventsService, TEventsImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.EventsService = typeof(TEventsService);
|
||||||
|
source.EventsImplementation = typeof(TEventsImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddKeyGenerator<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.KeyGeneratorService = typeof(TKeyGeneratorService);
|
||||||
|
source.KeyGeneratorImplementation = typeof(TKeyGeneratorImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddSeeder<TEntity, TKey, TSeederService, TSeederImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.SeederService = typeof(TSeederService);
|
||||||
|
source.SeederImplementation = typeof(TSeederImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddEFRepository<TEntity, TKey, TContext, TRepositoryService, TRepositoryImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TContext : XDbContext
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.RepositoryService = typeof(TRepositoryService);
|
||||||
|
source.RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddMongoRepository<TEntity, TKey, TRepositoryService, TRepositoryImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseMongoRepository<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.RepositoryService = typeof(TRepositoryService);
|
||||||
|
source.RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XRepositoryDescriptor AddInMemoryRepository<TEntity, TKey, TRepositoryService, TRepositoryImplementation>(
|
||||||
|
this XRepositoryDescriptor source
|
||||||
|
)
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (source.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source = new XRepositoryDescriptor();
|
||||||
|
source = source.AddEntity<TEntity, TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
source.RepositoryService = typeof(TRepositoryService);
|
||||||
|
source.RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+505
-53
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using GraphQL.Server;
|
using GraphQL.Server;
|
||||||
|
using GraphQL.Server.Ui.Playground;
|
||||||
using GraphQL.Types;
|
using GraphQL.Types;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -448,7 +449,7 @@ namespace xDataService.Helpers
|
|||||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
where TRepositoryImplementation : XBaseInMemoryRepositoy<TEntity, TKey>
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -513,6 +514,144 @@ namespace xDataService.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register Repository ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="repositoryDescriptor"></param>
|
||||||
|
/// <param name="lifetime"></param>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorService"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TEventsService"></typeparam>
|
||||||
|
/// <typeparam name="TEventsImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraph"></typeparam>
|
||||||
|
/// <typeparam name="TGraphKey"></typeparam>
|
||||||
|
/// <typeparam name="TGraphQuery"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperService"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraphSchema"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryService"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TSeederService"></typeparam>
|
||||||
|
/// <typeparam name="TSeederImplementation"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void AddXRepository<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
>(
|
||||||
|
IServiceCollection source,
|
||||||
|
XInMemoryRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TSeederService, TSeederImplementation> repositoryDescriptor,
|
||||||
|
ServiceLifetime lifetime = ServiceLifetime.Scoped
|
||||||
|
)
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var isValid = repositoryDescriptor.IsValid();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register KeyGenerator ...
|
||||||
|
isValid = repositoryDescriptor.HasKeyGenerator();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXKeyGenerator<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Events ...
|
||||||
|
isValid = repositoryDescriptor.HasEvents();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXEvents<TEntity, TKey, TEventsService, TEventsImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Graph ...
|
||||||
|
isValid = repositoryDescriptor.HasGraphSupport();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Repository ...
|
||||||
|
isValid = repositoryDescriptor.HasRepository();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.RepositoryService,
|
||||||
|
repositoryDescriptor.RepositoryImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DbSeeder ...
|
||||||
|
isValid = repositoryDescriptor.HasSeeder();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.SeederService,
|
||||||
|
repositoryDescriptor.SeederImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Repository ...
|
/// Register Repository ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -630,6 +769,144 @@ namespace xDataService.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register Repository ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="repositoryDescriptor"></param>
|
||||||
|
/// <param name="lifetime"></param>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorService"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TEventsService"></typeparam>
|
||||||
|
/// <typeparam name="TEventsImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraph"></typeparam>
|
||||||
|
/// <typeparam name="TGraphKey"></typeparam>
|
||||||
|
/// <typeparam name="TGraphQuery"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperService"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraphSchema"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryService"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TSeederService"></typeparam>
|
||||||
|
/// <typeparam name="TSeederImplementation"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void AddXRepository<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
>(
|
||||||
|
IServiceCollection source,
|
||||||
|
XMongoRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TSeederService, TSeederImplementation> repositoryDescriptor,
|
||||||
|
ServiceLifetime lifetime = ServiceLifetime.Scoped
|
||||||
|
)
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseMongoRepository<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var isValid = repositoryDescriptor.IsValid();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register KeyGenerator ...
|
||||||
|
isValid = repositoryDescriptor.HasKeyGenerator();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXKeyGenerator<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Events ...
|
||||||
|
isValid = repositoryDescriptor.HasEvents();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXEvents<TEntity, TKey, TEventsService, TEventsImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Graph ...
|
||||||
|
isValid = repositoryDescriptor.HasGraphSupport();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Repository ...
|
||||||
|
isValid = repositoryDescriptor.HasRepository();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.RepositoryService,
|
||||||
|
repositoryDescriptor.RepositoryImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DbSeeder ...
|
||||||
|
isValid = repositoryDescriptor.HasSeeder();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.SeederService,
|
||||||
|
repositoryDescriptor.SeederImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Repository ...
|
/// Register Repository ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -750,6 +1027,147 @@ namespace xDataService.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register Repository ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="repositoryDescriptor"></param>
|
||||||
|
/// <param name="lifetime"></param>
|
||||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorService"></typeparam>
|
||||||
|
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TEventsService"></typeparam>
|
||||||
|
/// <typeparam name="TEventsImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraph"></typeparam>
|
||||||
|
/// <typeparam name="TGraphKey"></typeparam>
|
||||||
|
/// <typeparam name="TGraphQuery"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperService"></typeparam>
|
||||||
|
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TGraphSchema"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryService"></typeparam>
|
||||||
|
/// <typeparam name="TRepositoryImplementation"></typeparam>
|
||||||
|
/// <typeparam name="TContext"></typeparam>
|
||||||
|
/// <typeparam name="TSeederService"></typeparam>
|
||||||
|
/// <typeparam name="TSeederImplementation"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void AddXRepository<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TContext,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
>(
|
||||||
|
IServiceCollection source,
|
||||||
|
XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext, TSeederService, TSeederImplementation> repositoryDescriptor,
|
||||||
|
ServiceLifetime lifetime = ServiceLifetime.Scoped
|
||||||
|
)
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TContext : XDbContext
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var isValid = repositoryDescriptor.IsValid();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register KeyGenerator ...
|
||||||
|
isValid = repositoryDescriptor.HasKeyGenerator();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXKeyGenerator<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Events ...
|
||||||
|
isValid = repositoryDescriptor.HasEvents();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXEvents<TEntity, TKey, TEventsService, TEventsImplementation>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Graph ...
|
||||||
|
isValid = repositoryDescriptor.HasGraphSupport();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
||||||
|
source,
|
||||||
|
repositoryDescriptor,
|
||||||
|
lifetime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Repository ...
|
||||||
|
isValid = repositoryDescriptor.HasRepository();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.RepositoryService,
|
||||||
|
repositoryDescriptor.RepositoryImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DbSeeder ...
|
||||||
|
isValid = repositoryDescriptor.HasSeeder();
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.Add(
|
||||||
|
new ServiceDescriptor(
|
||||||
|
repositoryDescriptor.SeederService,
|
||||||
|
repositoryDescriptor.SeederImplementation,
|
||||||
|
lifetime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Repository ...
|
/// Register Repository ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -800,7 +1218,7 @@ namespace xDataService.Helpers
|
|||||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
where TRepositoryImplementation : XBaseInMemoryRepositoy<TEntity, TKey>
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
{
|
{
|
||||||
@@ -898,79 +1316,113 @@ namespace xDataService.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Register Repository ...
|
// /// Register Repository ...
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <param name="source"></param>
|
// /// <param name="source"></param>
|
||||||
/// <param name="repositoryDescriptor"></param>
|
// /// <param name="repositoryDescriptor"></param>
|
||||||
/// <typeparam name="TEntity"></typeparam>
|
// /// <typeparam name="TEntity"></typeparam>
|
||||||
/// <typeparam name="TKey"></typeparam>
|
// /// <typeparam name="TKey"></typeparam>
|
||||||
/// <typeparam name="TKeyGeneratorService"></typeparam>
|
// /// <typeparam name="TKeyGeneratorService"></typeparam>
|
||||||
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
|
// /// <typeparam name="TKeyGeneratorImplementation"></typeparam>
|
||||||
/// <typeparam name="TEventsService"></typeparam>
|
// /// <typeparam name="TEventsService"></typeparam>
|
||||||
/// <typeparam name="TEventsImplementation"></typeparam>
|
// /// <typeparam name="TEventsImplementation"></typeparam>
|
||||||
/// <typeparam name="TGraph"></typeparam>
|
// /// <typeparam name="TGraph"></typeparam>
|
||||||
/// <typeparam name="TGraphKey"></typeparam>
|
// /// <typeparam name="TGraphKey"></typeparam>
|
||||||
/// <typeparam name="TGraphQuery"></typeparam>
|
// /// <typeparam name="TGraphQuery"></typeparam>
|
||||||
/// <typeparam name="TGraphTypeHelperService"></typeparam>
|
// /// <typeparam name="TGraphTypeHelperService"></typeparam>
|
||||||
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
|
// /// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
|
||||||
/// <typeparam name="TGraphSchema"></typeparam>
|
// /// <typeparam name="TGraphSchema"></typeparam>
|
||||||
/// <typeparam name="TRepositoryService"></typeparam>
|
// /// <typeparam name="TRepositoryService"></typeparam>
|
||||||
/// <typeparam name="TRepositoryImplementation"></typeparam>
|
// /// <typeparam name="TRepositoryImplementation"></typeparam>
|
||||||
/// <typeparam name="TContext"></typeparam>
|
// /// <typeparam name="TContext"></typeparam>
|
||||||
/// <returns></returns>
|
// /// <returns></returns>
|
||||||
public static void UseXRepository<
|
// public static void UseXRepository<
|
||||||
|
// TEntity,
|
||||||
|
// TKey,
|
||||||
|
// TKeyGeneratorService,
|
||||||
|
// TKeyGeneratorImplementation,
|
||||||
|
// TEventsService,
|
||||||
|
// TEventsImplementation,
|
||||||
|
// TGraph,
|
||||||
|
// TGraphKey,
|
||||||
|
// TGraphQuery,
|
||||||
|
// TGraphTypeHelperService,
|
||||||
|
// TGraphTypeHelperImplementation,
|
||||||
|
// TGraphSchema,
|
||||||
|
// TRepositoryService,
|
||||||
|
// TRepositoryImplementation,
|
||||||
|
// TContext
|
||||||
|
// >(
|
||||||
|
// IApplicationBuilder source,
|
||||||
|
// XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext> repositoryDescriptor
|
||||||
|
// )
|
||||||
|
// where TGraphSchema : Schema
|
||||||
|
// where TContext : XDbContext
|
||||||
|
// where TGraphKey : IGraphType
|
||||||
|
// where TEntity : XBaseEntity<TKey>
|
||||||
|
// where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
// where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
// where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
// where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
// where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
// where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
// where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
// where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
// where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
||||||
|
// where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// var isValid = repositoryDescriptor.IsValid();
|
||||||
|
// if (!isValid)
|
||||||
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // GraphQL ...
|
||||||
|
// isValid = repositoryDescriptor.HasGraphSupport();
|
||||||
|
// if (isValid)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
||||||
|
// source,
|
||||||
|
// repositoryDescriptor
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static void UseXGraphQL<
|
||||||
TEntity,
|
TEntity,
|
||||||
TKey,
|
TKey,
|
||||||
TKeyGeneratorService,
|
|
||||||
TKeyGeneratorImplementation,
|
|
||||||
TEventsService,
|
|
||||||
TEventsImplementation,
|
|
||||||
TGraph,
|
TGraph,
|
||||||
TGraphKey,
|
TGraphKey,
|
||||||
TGraphQuery,
|
TGraphQuery,
|
||||||
TGraphTypeHelperService,
|
TGraphTypeHelperService,
|
||||||
TGraphTypeHelperImplementation,
|
TGraphTypeHelperImplementation,
|
||||||
TGraphSchema,
|
TGraphSchema
|
||||||
TRepositoryService,
|
|
||||||
TRepositoryImplementation,
|
|
||||||
TContext
|
|
||||||
>(
|
>(
|
||||||
IApplicationBuilder source,
|
IApplicationBuilder source,
|
||||||
XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext> repositoryDescriptor
|
string graphPath,
|
||||||
|
bool withPlayGround = false,
|
||||||
|
GraphQLPlaygroundOptions options = null
|
||||||
)
|
)
|
||||||
where TGraphSchema : Schema
|
where TGraphSchema : Schema
|
||||||
where TContext : XDbContext
|
|
||||||
where TGraphKey : IGraphType
|
where TGraphKey : IGraphType
|
||||||
where TEntity : XBaseEntity<TKey>
|
where TEntity : XBaseEntity<TKey>
|
||||||
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
|
||||||
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
|
||||||
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
|
||||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
|
||||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
|
||||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
|
||||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var isValid = repositoryDescriptor.IsValid();
|
source.UseGraphQL<TGraphSchema>(graphPath);
|
||||||
if (!isValid)
|
source.UseGraphQLWebSockets<TGraphSchema>();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// GraphQL ...
|
if (withPlayGround)
|
||||||
isValid = repositoryDescriptor.HasGraphSupport();
|
|
||||||
if (isValid)
|
|
||||||
{
|
{
|
||||||
//
|
source.UseGraphQLPlayground(options);
|
||||||
UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
|
||||||
source,
|
|
||||||
repositoryDescriptor
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ namespace xDataService.InMemRepositories
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TEntity"></typeparam>
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
/// <typeparam name="TKey"></typeparam>
|
/// <typeparam name="TKey"></typeparam>
|
||||||
public abstract class XBaseInMemoryRepositoy<TEntity, TKey> : IXBaseRepository<TEntity, TKey>
|
public abstract class XBaseInMemoryRepository<TEntity, TKey> : IXBaseRepository<TEntity, TKey>
|
||||||
where TEntity : XBaseEntity<TKey>
|
where TEntity : XBaseEntity<TKey>
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -36,7 +36,7 @@ namespace xDataService.InMemRepositories
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Constructor ...
|
#region Constructor ...
|
||||||
public XBaseInMemoryRepositoy(
|
public XBaseInMemoryRepository(
|
||||||
XDataServiceConfiguration configuration,
|
XDataServiceConfiguration configuration,
|
||||||
IXKeyGenerator<TEntity, TKey> keyGenerator = null,
|
IXKeyGenerator<TEntity, TKey> keyGenerator = null,
|
||||||
IXBaseRepositoryEvents<TEntity> baseRepositoryEvents = null
|
IXBaseRepositoryEvents<TEntity> baseRepositoryEvents = null
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xDataService.Configuration;
|
using xDataService.Configuration;
|
||||||
|
using xModels.Base;
|
||||||
|
|
||||||
namespace xDataService.Interfaces {
|
namespace xDataService.Interfaces
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Db Seeder used to seed data on Database on startup time ...
|
/// Db Seeder used to seed data on Database on startup time ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IXDbSeeder {
|
public interface IXBaseDbSeeder<TEntity, TKey>
|
||||||
IXDbSeederConfig Config { get; }
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
{
|
||||||
|
string Database { get; }
|
||||||
|
|
||||||
|
IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||||
|
|
||||||
XDataServiceConfiguration DataServiceConfiguration { get; }
|
XDataServiceConfiguration DataServiceConfiguration { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// do all seeding action by helping of Repositories here ...
|
/// do all seeding action by helping of Repositories here ...
|
||||||
/// don't forget to check UpdateExists value on IXDbSeederConfig for prevent system of duplicate Entity adding on startups ...
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task Seed();
|
Task Seed();
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using MongoDB.Bson.Serialization.Conventions;
|
|
||||||
using xDataService.Constants;
|
|
||||||
|
|
||||||
namespace xDataService.Interfaces {
|
|
||||||
public interface IXDataServiceHelper {
|
|
||||||
/// <summary>
|
|
||||||
/// register DbContext implementation on DI Container ...
|
|
||||||
/// Only Used in EFCore ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="connectionString"></param>
|
|
||||||
/// <param name="dbProvider"></param>
|
|
||||||
/// <param name="lifetime"></param>
|
|
||||||
/// <param name="optionsBuilder"></param>
|
|
||||||
void AddDbContext (
|
|
||||||
IServiceCollection services,
|
|
||||||
string connectionString,
|
|
||||||
XDbProviders dbProvider,
|
|
||||||
ServiceLifetime lifetime,
|
|
||||||
Action<dynamic> optionsBuilder = null
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// register all Entities Repositories and Events on DI Container ...
|
|
||||||
/// implementations of IXBaseRepository and IXBaseRepositoryEvent ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="lifetime"></param>
|
|
||||||
void AddRepositories (
|
|
||||||
IServiceCollection services,
|
|
||||||
ServiceLifetime lifetime
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Regitster KeyGenerators for Repositories ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
void AddKeyGenerators (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// register DBSeeder Configuration on DI Container ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
void AddDbSeederConfiguration (
|
|
||||||
IServiceCollection services,
|
|
||||||
IConfiguration configuration
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// register Data Seeder on DI Container ...
|
|
||||||
/// implementation of IXDbSeeder ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="config"></param>
|
|
||||||
/// <param name="lifetime"></param>
|
|
||||||
/// <typeparam name="TDbSeeder"></typeparam>
|
|
||||||
void AddDbSeeder<TDbSeeder> (
|
|
||||||
IServiceCollection services,
|
|
||||||
IConfiguration config,
|
|
||||||
ServiceLifetime lifetime
|
|
||||||
) where TDbSeeder : IXDbSeeder;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set Mongo Convention Pack ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
ConventionPack MongoConventionPacks ();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configure all required MongoDb Class Mappers and etc here ...
|
|
||||||
/// </summary>
|
|
||||||
void RegisterMongoExtras ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace xDataService.Interfaces {
|
|
||||||
/// <summary>
|
|
||||||
/// this Configuration used to Carry all Entity Descriptors collections
|
|
||||||
/// can readable by appSettings.json file for providing dynamic data seeding ...
|
|
||||||
/// </summary>
|
|
||||||
public interface IXDbSeederConfig {
|
|
||||||
/// <summary>
|
|
||||||
/// determines an Entity can Update when Exists or not ...
|
|
||||||
/// this must handled by consumer on IXDbSeeder Seed method implementation ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
bool UpdateExists { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
using GraphQL.Server;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace xDataService.Interfaces {
|
|
||||||
/// <summary>
|
|
||||||
/// this is a helper class which provides all requirements to providing GraphQL
|
|
||||||
/// based data manipulating mechanism ...
|
|
||||||
/// </summary>
|
|
||||||
public interface IXGraphQLHelper {
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Enum Types ...
|
|
||||||
/// Enum Types use to Map string values to Enum values in propper way and vise versa in GraphQL ...
|
|
||||||
/// must extended from EnumerationGraphType ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphEnumTypes (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Object Types ...
|
|
||||||
/// GraphQL works based on Types, so for representing each data you have to define a Type ...
|
|
||||||
/// must extended from ObjectGraphType<T> or XBaseGraphObjectType<TKey>
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphObjectTypes (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Input Types ...
|
|
||||||
/// InputTypes represent recieving data structure in GraphQL for doing mutations ...
|
|
||||||
/// must extended from InputObjectGraphType<T> ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphInputTypes (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Queries ...
|
|
||||||
/// Queries in GraphQL used to provide data fetch and retrieve mechanism ...
|
|
||||||
/// extended from ObjectGraphType ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphQueries (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Mutations ...
|
|
||||||
/// Mutations is an Action types in GraphQL which data changed through them, like as Add, Update, Delete ...
|
|
||||||
/// must extends from ObjectGraphType ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphMutations (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Subscriptions ...
|
|
||||||
/// Subscriptions are listeners to specific events on data in GraphQL ...
|
|
||||||
/// must extended from ObjectGraphType and implements IXBaseRepositoryEvents<TEntity> ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphSubscriptions (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register all GraphQL Schemas ...
|
|
||||||
/// each available Entity in Database must described to GraphQL with all Graph based stuffs such as :
|
|
||||||
/// Queries, Types and etc, this must done through an Schema class.
|
|
||||||
/// must extended from Schema ...
|
|
||||||
/// </summary>
|
|
||||||
void AddXGraphSchemas (IServiceCollection services);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add Schemas to GraphQL Builder ...
|
|
||||||
/// here you must add all registered Schemas to GraphQLBuilder ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="builder"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IGraphQLBuilder AddXGraphTypes (IGraphQLBuilder builder);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use all Registered Schemas by GraphQL<T> and and GraphQLWebSockets<T> ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app"></param>
|
|
||||||
void UseXGraph (IApplicationBuilder app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -99,13 +99,23 @@ namespace xDataService.Models
|
|||||||
/// Repository Data Access Design Pattern ...
|
/// Repository Data Access Design Pattern ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public Type RepositoryService { get; set; }
|
public Type RepositoryService { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Repository Data Access Design Pattern ...
|
/// Repository Data Access Design Pattern ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public Type RepositoryImplementation { get; set; }
|
public Type RepositoryImplementation { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Database Data Seeder ...
|
||||||
|
/// </summary>
|
||||||
|
public Type SeederService { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Database Data Seeder ...
|
||||||
|
/// </summary>
|
||||||
|
public Type SeederImplementation { get; set; } = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -265,7 +275,7 @@ namespace xDataService.Models
|
|||||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
where TRepositoryImplementation : XBaseInMemoryRepositoy<TEntity, TKey>
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
{
|
{
|
||||||
@@ -277,6 +287,68 @@ namespace xDataService.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Repository Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
public class XInMemoryRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
> : XRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema
|
||||||
|
>
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
public XInMemoryRepositoryDescriptor() : base()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
SeederService = typeof(TSeederService);
|
||||||
|
SeederImplementation = typeof(TSeederImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
RepositoryService = typeof(TRepositoryService);
|
||||||
|
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a Repository Descriptor ...
|
/// a Repository Descriptor ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -331,6 +403,68 @@ namespace xDataService.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Repository Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
public class XMongoRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
> : XRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema
|
||||||
|
>
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryImplementation : XBaseMongoRepository<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
public XMongoRepositoryDescriptor() : base()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
SeederService = typeof(TSeederService);
|
||||||
|
SeederImplementation = typeof(TSeederImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
RepositoryService = typeof(TRepositoryService);
|
||||||
|
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a Repository Descriptor ...
|
/// a Repository Descriptor ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -387,4 +521,69 @@ namespace xDataService.Models
|
|||||||
RepositoryImplementation = typeof(TRepositoryImplementation);
|
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Repository Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
public class XEFRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema,
|
||||||
|
TRepositoryService,
|
||||||
|
TRepositoryImplementation,
|
||||||
|
TContext,
|
||||||
|
TSeederService,
|
||||||
|
TSeederImplementation
|
||||||
|
> : XRepositoryDescriptor<
|
||||||
|
TEntity,
|
||||||
|
TKey,
|
||||||
|
TKeyGeneratorService,
|
||||||
|
TKeyGeneratorImplementation,
|
||||||
|
TEventsService,
|
||||||
|
TEventsImplementation,
|
||||||
|
TGraph,
|
||||||
|
TGraphKey,
|
||||||
|
TGraphQuery,
|
||||||
|
TGraphTypeHelperService,
|
||||||
|
TGraphTypeHelperImplementation,
|
||||||
|
TGraphSchema
|
||||||
|
>
|
||||||
|
where TGraphSchema : Schema
|
||||||
|
where TContext : XDbContext
|
||||||
|
where TGraphKey : IGraphType
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||||
|
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||||
|
where TRepositoryService : IXBaseRepository<TEntity, TKey>
|
||||||
|
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||||
|
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||||
|
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||||
|
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
||||||
|
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||||
|
{
|
||||||
|
public XEFRepositoryDescriptor() : base()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
SeederService = typeof(TSeederService);
|
||||||
|
SeederImplementation = typeof(TSeederImplementation);
|
||||||
|
|
||||||
|
//
|
||||||
|
Context = typeof(TContext);
|
||||||
|
RepositoryService = typeof(TRepositoryService);
|
||||||
|
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xDataService.Constants;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xModels.Base;
|
||||||
|
|
||||||
|
namespace xDataService.Providers
|
||||||
|
{
|
||||||
|
public abstract class XBaseDbSeeder<TEntity, TKey> : IXBaseDbSeeder<TEntity, TKey>
|
||||||
|
where TEntity : XBaseEntity<TKey>
|
||||||
|
{
|
||||||
|
public string Database { get; }
|
||||||
|
|
||||||
|
public IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||||
|
|
||||||
|
public XDataServiceConfiguration DataServiceConfiguration { get; }
|
||||||
|
|
||||||
|
public XBaseDbSeeder(
|
||||||
|
string database,
|
||||||
|
IXBaseRepository<TEntity, TKey> repository,
|
||||||
|
XDataServiceConfiguration dataServiceConfiguration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
this.Database = database;
|
||||||
|
this.Repository = repository;
|
||||||
|
this.DataServiceConfiguration = dataServiceConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Seed()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var entityName = nameof(TEntity);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Seed ...
|
||||||
|
var isValid =
|
||||||
|
DataServiceConfiguration.SeedingMode != XDbSeedingMode.None &&
|
||||||
|
DataServiceConfiguration
|
||||||
|
.Databases
|
||||||
|
.Any(db =>
|
||||||
|
db.Key == Database &&
|
||||||
|
db.Value.SeedItems
|
||||||
|
.Any(si =>
|
||||||
|
si.Key == entityName &&
|
||||||
|
si.Value.HasChild()));
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Extract Seeding Items ...
|
||||||
|
var seedItems = DataServiceConfiguration
|
||||||
|
.Databases[Database]
|
||||||
|
.SeedItems[entityName]
|
||||||
|
.ToList();
|
||||||
|
foreach (var item in seedItems)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Try to convert Item to Entity ...
|
||||||
|
var entity = ((object)item).FromDynamicObject<TEntity>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Item Exists or not ...
|
||||||
|
var isExist = false;
|
||||||
|
TEntity exists = null;
|
||||||
|
var asyncEnumerable = this.Repository.GetAllAsAsyncEnumerable();
|
||||||
|
await foreach (var e in asyncEnumerable)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
isExist = e.IsSameContent(
|
||||||
|
dest: entity,
|
||||||
|
propertyBlackList: new List<string>
|
||||||
|
{
|
||||||
|
nameof(entity.Id),
|
||||||
|
nameof(entity.Deleted)
|
||||||
|
});
|
||||||
|
if (isExist)
|
||||||
|
{
|
||||||
|
exists = e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Seed Based on Seed Mode ...
|
||||||
|
var seedMode = DataServiceConfiguration.SeedingMode;
|
||||||
|
switch (seedMode)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
case XDbSeedingMode.AddIfNotExists:
|
||||||
|
//
|
||||||
|
if (!isExist)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists = await Repository.AddAsync(entity);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case XDbSeedingMode.AddOrUpdate:
|
||||||
|
//
|
||||||
|
exists = exists.UpdateData(
|
||||||
|
updateWith: entity,
|
||||||
|
propertyBlackList: new List<string>
|
||||||
|
{
|
||||||
|
nameof(entity.Id),
|
||||||
|
nameof(entity.Deleted)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
await Repository.AddOrUpdateAsync(exists);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user