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;
|
||||
|
||||
namespace xDataService.Configuration
|
||||
@@ -17,6 +18,12 @@ namespace xDataService.Configuration
|
||||
/// Connection String which provide Requires Data to Connect to Db Provider ...
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// <typeparam name="XDataBaseConfiguration"></typeparam>
|
||||
/// <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>
|
||||
/// Enable Soft Delete Entities or Not ...
|
||||
@@ -27,6 +27,11 @@ namespace xDataService.Configuration
|
||||
/// <value></value>
|
||||
public bool EnableSoftDelete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specified Seeding Mode ...
|
||||
/// </summary>
|
||||
public XDbSeedingMode SeedingMode { get; set; } = XDbSeedingMode.None;
|
||||
|
||||
/// <summary>
|
||||
/// Enable Tracking of Entities ...
|
||||
/// 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,
|
||||
}
|
||||
}
|
||||
+79
-83
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -11,7 +11,6 @@ using xDataService.Configuration;
|
||||
using xDataService.Constants;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Helpers;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Models;
|
||||
using xExceptions.Constants;
|
||||
|
||||
@@ -34,6 +33,25 @@ namespace xDataService.DI
|
||||
.GetSection(ConfigurationNodeNames.DATA_SERVICE_NODE);
|
||||
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;
|
||||
}
|
||||
@@ -229,7 +247,8 @@ namespace xDataService.DI
|
||||
|
||||
public static void UseXDatabase(
|
||||
this IApplicationBuilder source,
|
||||
XDatabaseDescriptor descriptor
|
||||
XDatabaseDescriptor descriptor,
|
||||
bool isDevelopmentEnvironment = false
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -244,6 +263,14 @@ namespace xDataService.DI
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var withPlayground = false;
|
||||
if (isDevelopmentEnvironment)
|
||||
{
|
||||
//
|
||||
withPlayground = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Repositories Exists ...
|
||||
isValid = descriptor.HasRepositories();
|
||||
@@ -265,61 +292,66 @@ namespace xDataService.DI
|
||||
.ToList()
|
||||
.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 ...
|
||||
isValid = r.HasGraphSupport();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Inject GraphQL Type Helper ...
|
||||
var helper = scope.ServiceProvider.GetService(r.GraphTypeHelperService);
|
||||
isValid = !helper.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
//
|
||||
Log($"unable to find GraphQLTypeHelper for Entiy: {r.Entity}");
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
// Use WebSockets ...
|
||||
source.UseWebSockets();
|
||||
|
||||
//
|
||||
var methods = source.GetType().GetMethods();
|
||||
isValid =
|
||||
!methods.IsNull() &&
|
||||
methods.HasChild();
|
||||
// Inject GraphQL Type Helper ...
|
||||
var helper = (dynamic)scope.ServiceProvider.GetService(r.GraphTypeHelperService);
|
||||
isValid = helper != null;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// UseGraphQL ...
|
||||
var method = methods.First(m =>
|
||||
m.IsGenericMethod &&
|
||||
m.Name == "UseGraphQL" &&
|
||||
m.GetGenericArguments().Length == 1 &&
|
||||
m.GetParameters().Length == 1
|
||||
);
|
||||
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} ...");
|
||||
}
|
||||
string graphPath = helper.GetGraphQLPath();
|
||||
typeof(XDataServiceHelper).InvokeGenericMethod(
|
||||
methodName: "UseXGraphQL",
|
||||
runtimeTypes: [
|
||||
r.Entity,
|
||||
r.Key,
|
||||
r.GraphType,
|
||||
r.GraphTypeKey,
|
||||
r.GraphQuery,
|
||||
r.GraphTypeHelperService,
|
||||
r.GraphTypeHelperImplementation,
|
||||
r.GraphSchema
|
||||
],
|
||||
args: [
|
||||
source,
|
||||
graphPath,
|
||||
withPlayground,
|
||||
null
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -343,42 +375,6 @@ namespace xDataService.DI
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Db;
|
||||
using xDataService.EFRepositories;
|
||||
using xDataService.Events;
|
||||
using xDataService.InMemRepositories;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Models;
|
||||
using xDataService.MongoRepositories;
|
||||
using xDataService.Providers;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Extensions
|
||||
{
|
||||
public static class XRepositoryDescriptorExtensions
|
||||
{
|
||||
//
|
||||
#region Hasers ...
|
||||
/// <summary>
|
||||
/// Validate a Descriptor ...
|
||||
/// </summary>
|
||||
@@ -64,6 +74,7 @@ namespace xDataService.Extensions
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
source.HasRepository() &&
|
||||
!source.GraphType.IsNull() &&
|
||||
!source.GraphQuery.IsNull() &&
|
||||
!source.GraphSchema.IsNull() &&
|
||||
@@ -108,5 +119,185 @@ namespace xDataService.Extensions
|
||||
//
|
||||
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 GraphQL.Server;
|
||||
using GraphQL.Server.Ui.Playground;
|
||||
using GraphQL.Types;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -448,7 +449,7 @@ namespace xDataService.Helpers
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TRepositoryImplementation : XBaseInMemoryRepositoy<TEntity, TKey>
|
||||
where TRepositoryImplementation : XBaseInMemoryRepository<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>
|
||||
/// Register Repository ...
|
||||
/// </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>
|
||||
/// Register Repository ...
|
||||
/// </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>
|
||||
/// Register Repository ...
|
||||
/// </summary>
|
||||
@@ -800,7 +1218,7 @@ namespace xDataService.Helpers
|
||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<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 TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
{
|
||||
@@ -898,79 +1316,113 @@ namespace xDataService.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Repository ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="repositoryDescriptor"></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>
|
||||
/// <returns></returns>
|
||||
public static void UseXRepository<
|
||||
// /// <summary>
|
||||
// /// Register Repository ...
|
||||
// /// </summary>
|
||||
// /// <param name="source"></param>
|
||||
// /// <param name="repositoryDescriptor"></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>
|
||||
// /// <returns></returns>
|
||||
// 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,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema,
|
||||
TRepositoryService,
|
||||
TRepositoryImplementation,
|
||||
TContext
|
||||
TGraphSchema
|
||||
>(
|
||||
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 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;
|
||||
}
|
||||
source.UseGraphQL<TGraphSchema>(graphPath);
|
||||
source.UseGraphQLWebSockets<TGraphSchema>();
|
||||
|
||||
//
|
||||
// GraphQL ...
|
||||
isValid = repositoryDescriptor.HasGraphSupport();
|
||||
if (isValid)
|
||||
if (withPlayGround)
|
||||
{
|
||||
//
|
||||
UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
|
||||
source,
|
||||
repositoryDescriptor
|
||||
);
|
||||
source.UseGraphQLPlayground(options);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ namespace xDataService.InMemRepositories
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></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>
|
||||
{
|
||||
//
|
||||
@@ -36,7 +36,7 @@ namespace xDataService.InMemRepositories
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XBaseInMemoryRepositoy(
|
||||
public XBaseInMemoryRepository(
|
||||
XDataServiceConfiguration configuration,
|
||||
IXKeyGenerator<TEntity, TKey> keyGenerator = null,
|
||||
IXBaseRepositoryEvents<TEntity> baseRepositoryEvents = null
|
||||
@@ -1,19 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using xDataService.Configuration;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
namespace xDataService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Db Seeder used to seed data on Database on startup time ...
|
||||
/// </summary>
|
||||
public interface IXDbSeeder {
|
||||
IXDbSeederConfig Config { get; }
|
||||
public interface IXBaseDbSeeder<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
string Database { get; }
|
||||
|
||||
IXBaseRepository<TEntity, TKey> Repository { get; }
|
||||
|
||||
XDataServiceConfiguration DataServiceConfiguration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
+283
-84
@@ -99,13 +99,23 @@ namespace xDataService.Models
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type RepositoryService { get; set; }
|
||||
public Type RepositoryService { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -128,9 +138,9 @@ namespace xDataService.Models
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation
|
||||
> : XRepositoryDescriptor<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
@@ -149,16 +159,16 @@ namespace xDataService.Models
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation
|
||||
> : XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation
|
||||
>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
@@ -179,24 +189,24 @@ namespace xDataService.Models
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema
|
||||
> : XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation
|
||||
>
|
||||
where TGraphSchema : Schema
|
||||
@@ -227,32 +237,32 @@ namespace xDataService.Models
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XInMemoryRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema,
|
||||
TRepositoryService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema,
|
||||
TRepositoryService,
|
||||
TRepositoryImplementation
|
||||
> : XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema
|
||||
>
|
||||
where TGraphSchema : Schema
|
||||
@@ -265,7 +275,7 @@ namespace xDataService.Models
|
||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<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 TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
{
|
||||
@@ -277,36 +287,98 @@ 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>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XMongoRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema,
|
||||
TRepositoryService,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema,
|
||||
TRepositoryService,
|
||||
TRepositoryImplementation
|
||||
> : XRepositoryDescriptor<
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TEntity,
|
||||
TKey,
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema
|
||||
>
|
||||
where TGraphSchema : Schema
|
||||
@@ -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>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
@@ -356,12 +490,12 @@ namespace xDataService.Models
|
||||
TKeyGeneratorService,
|
||||
TKeyGeneratorImplementation,
|
||||
TEventsService,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TEventsImplementation,
|
||||
TGraph,
|
||||
TGraphKey,
|
||||
TGraphQuery,
|
||||
TGraphTypeHelperService,
|
||||
TGraphTypeHelperImplementation,
|
||||
TGraphSchema
|
||||
>
|
||||
where TGraphSchema : Schema
|
||||
@@ -387,4 +521,69 @@ namespace xDataService.Models
|
||||
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