last ...
This commit is contained in:
+155
-85
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
@@ -10,7 +9,7 @@ using xCommons.Extensions;
|
||||
using xCommons.Helpers;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Constants;
|
||||
using xDataService.Db;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Helpers;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Models;
|
||||
@@ -84,6 +83,13 @@ namespace xDataService.DI
|
||||
source.AddSingleton(configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a Data Base using Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="descriptor"></param>
|
||||
/// <param name="lifetime"></param>
|
||||
public static void AddXDatabase(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration,
|
||||
@@ -162,35 +168,165 @@ namespace xDataService.DI
|
||||
!descriptor.ConnectionString.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
typeof(XDataServiceHelper).InvokeGenericMethod(
|
||||
methodName: "AddXDbContext",
|
||||
runtimeType: descriptor.Context,
|
||||
args: [
|
||||
source,
|
||||
try
|
||||
{
|
||||
//
|
||||
typeof(XDataServiceHelper).InvokeGenericMethod(
|
||||
methodName: "AddXDbContext",
|
||||
runtimeType: descriptor.Context,
|
||||
args: [
|
||||
source,
|
||||
descriptor.Provider,
|
||||
descriptor.ConnectionString,
|
||||
lifetime,
|
||||
descriptor.OptionsBuilder
|
||||
]
|
||||
);
|
||||
]
|
||||
);
|
||||
|
||||
//
|
||||
// source.AddXDbContext<TContext>(
|
||||
// lifetime: lifetime,
|
||||
// provider: descriptor.Provider,
|
||||
// optionsBuilder: descriptor.OptionsBuilder,
|
||||
// connectionString: descriptor.ConnectionString
|
||||
// );
|
||||
//
|
||||
Log($"DbContext: {descriptor.Name} Registered Successfully ...");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"DbContext: {descriptor.Name} Registration failed due {ex.Message} ...");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Register Repositories ...
|
||||
if (!descriptor.Repositories.IsNull() &&
|
||||
descriptor.Repositories.HasChild())
|
||||
{
|
||||
// source.AddXDataRepositories(
|
||||
//
|
||||
descriptor.Repositories.ToList().ForEach(r =>
|
||||
{
|
||||
//
|
||||
// Preparing Runtime Types ...
|
||||
Type[] runtimeTypes = r.GetType().GenericTypeArguments;
|
||||
|
||||
// );
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
typeof(XDataServiceHelper).InvokeGenericMethod(
|
||||
methodName: "AddXRepository",
|
||||
runtimeTypes: runtimeTypes,
|
||||
args: [
|
||||
source,
|
||||
r,
|
||||
lifetime
|
||||
]
|
||||
);
|
||||
|
||||
//
|
||||
Log($"Repository of: {runtimeTypes[0]}, Registered Successfully ...");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Repository of: {runtimeTypes[0]}, Registration failed due {ex.Message} ...");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void UseXDatabase(
|
||||
this IApplicationBuilder source,
|
||||
XDatabaseDescriptor descriptor
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!source.IsNull() &&
|
||||
descriptor.IsValid();
|
||||
if (!isValid)
|
||||
{
|
||||
//
|
||||
Log("Invalid Database Configuration ...");
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Repositories Exists ...
|
||||
isValid = descriptor.HasRepositories();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Create an Scope for Services Acces ...
|
||||
using (var scope = source.ApplicationServices.CreateScope())
|
||||
{
|
||||
//
|
||||
// Inject XDataServiceConfiguration ForMake Sure DataService Registration ...
|
||||
var dataServiceConfiguration = scope.ServiceProvider.GetService<XDataServiceConfiguration>();
|
||||
isValid = !dataServiceConfiguration.IsNullOrDefault();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Loop through Repositories ...
|
||||
descriptor.Repositories
|
||||
.ToList()
|
||||
.ForEach(r =>
|
||||
{
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
|
||||
//
|
||||
var methods = source.GetType().GetMethods();
|
||||
isValid =
|
||||
!methods.IsNull() &&
|
||||
methods.HasChild();
|
||||
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} ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,72 +346,6 @@ namespace xDataService.DI
|
||||
Console.WriteLine($"{XLogTag} => {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register DbContext ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="connectionString"></param>
|
||||
/// <param name="lifetime"></param>
|
||||
/// <param name="optionsBuilder"></param>
|
||||
/// <typeparam name="TContext"></typeparam>
|
||||
private static void AddXDbContext<TContext>(
|
||||
this IServiceCollection source,
|
||||
XDbProviders provider,
|
||||
string connectionString,
|
||||
ServiceLifetime lifetime = ServiceLifetime.Scoped,
|
||||
Action<dynamic> optionsBuilder = null
|
||||
)
|
||||
where TContext : XDbContext
|
||||
{
|
||||
//
|
||||
if (provider == XDbProviders.None)
|
||||
{
|
||||
//
|
||||
Log("Invalid Db Provider ...");
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
switch (provider)
|
||||
{
|
||||
//
|
||||
// MySQL ...
|
||||
case XDbProviders.MySQL:
|
||||
//
|
||||
source.AddDbContext<TContext>(cfg =>
|
||||
{
|
||||
cfg.UseMySQL(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
// SQLite ...
|
||||
case XDbProviders.SQLite:
|
||||
//
|
||||
source.AddDbContext<TContext>(cfg =>
|
||||
{
|
||||
cfg.UseSqlite(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
// SQLServer ...
|
||||
case XDbProviders.SQLServer:
|
||||
//
|
||||
source.AddDbContext<TContext>(cfg =>
|
||||
{
|
||||
cfg.UseSqlServer(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
case XDbProviders.MongoDB:
|
||||
// There is notRequired to Register DBConext forMongo DB ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do Seeding Initialization Data on DbContext
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Models;
|
||||
|
||||
namespace xDataService.Extensions
|
||||
{
|
||||
public static class XDatabaseDescriptorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate a Database Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid(this XDatabaseDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
!source.IsNull() &&
|
||||
!source.Name.IsNullOrEmpty();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has EF Core Context or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasContext(this XDatabaseDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.Context.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has Repositories or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasRepositories(this XDatabaseDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.Repositories.IsNull() &&
|
||||
source.Repositories.HasChild();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Models;
|
||||
|
||||
namespace xDataService.Extensions
|
||||
{
|
||||
public static class XRepositoryDescriptorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate a Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid(this XRepositoryDescriptor source)
|
||||
{
|
||||
var result =
|
||||
!source.IsNull() &&
|
||||
!source.Key.IsNull() &&
|
||||
!source.Entity.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has Events Service or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasEvents(this XRepositoryDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.EventsService.IsNull() &&
|
||||
!source.EventsImplementation.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has EF Core Context or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasContext(this XRepositoryDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.Context.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has GraphQL Support or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasGraphSupport(this XRepositoryDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.GraphType.IsNull() &&
|
||||
!source.GraphSchema.IsNull() &&
|
||||
!source.GraphTypeKey.IsNull() &&
|
||||
!source.GraphQueryService.IsNull() &&
|
||||
!source.GraphTypeHelperService.IsNull() &&
|
||||
!source.GraphQueryImplementation.IsNull() &&
|
||||
!source.GraphTypeHelperImplementation.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has Key Generator Service or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasKeyGenerator(this XRepositoryDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.KeyGeneratorService.IsNull() &&
|
||||
!source.KeyGeneratorImplementation.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Descriptor Has Repository Service or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasRepository(this XRepositoryDescriptor source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source.IsValid() &&
|
||||
!source.RepositoryService.IsNull() &&
|
||||
!source.RepositoryImplementation.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+252
-36
@@ -1,6 +1,13 @@
|
||||
using System;
|
||||
using GraphQL.Types;
|
||||
using xDataService.Db;
|
||||
using xDataService.EFRepositories;
|
||||
using xDataService.Events;
|
||||
using xDataService.GraphQL;
|
||||
using xDataService.InMemRepositories;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.MongoRepositories;
|
||||
using xDataService.Providers;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Models
|
||||
@@ -8,7 +15,104 @@ namespace xDataService.Models
|
||||
/// <summary>
|
||||
/// a Global non Generic Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor { }
|
||||
public class XRepositoryDescriptor
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity Key Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type Key { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type Entity { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Context Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type Context { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Graph Type Key ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphTypeKey { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Graph Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphType { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity Type GraphQL Schema ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphSchema { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type Helper ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphTypeHelperService { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type Helper ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphTypeHelperImplementation { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GrapQL Query ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphQueryService { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GrapQL Query ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type GraphQueryImplementation { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Event Provider ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type EventsService { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Event Provider ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type EventsImplementation { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Key Generator for Entity ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type KeyGeneratorService { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Key Generator for Entity ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type KeyGeneratorImplementation { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type RepositoryService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Type RepositoryImplementation { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
@@ -18,46 +122,158 @@ namespace xDataService.Models
|
||||
public class XRepositoryDescriptor<TEntity, TKey> : XRepositoryDescriptor
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity Type GraphQL Schema ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Schema GraphSchema { get; set; } = null;
|
||||
public XRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
Key = typeof(TKey);
|
||||
Entity = typeof(TEntity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type Helper ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseGraphQLTypeHelper GraphTypeHelper { get; set; } = null;
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation> : XRepositoryDescriptor<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||
{
|
||||
public XRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
KeyGeneratorService = typeof(TKeyGeneratorService);
|
||||
KeyGeneratorImplementation = typeof(TKeyGeneratorImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entity GrapQL Query ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseGraphQLQuery<TEntity, TKey> GraphQuery { get; set; } = null;
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation> : XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||
{
|
||||
public XRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
EventsService = typeof(TEventsService);
|
||||
EventsImplementation = typeof(TEventsImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public XBaseGraphObjectType<TEntity, TKey> GraphType { get; set; } = null;
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema> : XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation>
|
||||
where TGraphSchema : Schema
|
||||
where TGraphKey : IGraphType
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
where TGraph : XBaseGraphObjectType<TEntity, TKey>
|
||||
where TEventsService : IXBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
|
||||
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
|
||||
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
|
||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphQueryService : IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TGraphQueryImplementation : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
{
|
||||
public XRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
GraphType = typeof(TGraph);
|
||||
GraphTypeKey = typeof(TGraphKey);
|
||||
GraphSchema = typeof(TGraphSchema);
|
||||
GraphQueryService = typeof(TGraphQueryService);
|
||||
GraphTypeHelperService = typeof(TGraphTypeHelperService);
|
||||
GraphQueryImplementation = typeof(TGraphQueryImplementation);
|
||||
GraphTypeHelperImplementation = typeof(TGraphTypeHelperImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repository Event Provider ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseRepositoryEvents<TEntity> Events { get; set; } = null;
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XInMemoryRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation> : XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>
|
||||
where TGraphSchema : Schema
|
||||
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 TRepositoryImplementation : XBaseInMemoryRepositoy<TEntity, TKey>
|
||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphQueryService : IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TGraphQueryImplementation : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
{
|
||||
public XInMemoryRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
RepositoryService = typeof(TRepositoryService);
|
||||
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repository Key Generator for Entity ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXKeyGenerator<TEntity, TKey> KeyGenerator { get; set; } = null;
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XMongoRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation> : XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>
|
||||
where TGraphSchema : Schema
|
||||
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 TRepositoryImplementation : XBaseMongoRepository<TEntity, TKey>
|
||||
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphQueryService : IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TGraphQueryImplementation : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
{
|
||||
public XMongoRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
RepositoryService = typeof(TRepositoryService);
|
||||
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseRepository<TEntity, TKey> Repository { get; set; }
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext> : XRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQueryService, TGraphQueryImplementation, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>
|
||||
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 TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
|
||||
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TGraphQueryService : IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TGraphQueryImplementation : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
{
|
||||
public XEFRepositoryDescriptor() : base()
|
||||
{
|
||||
//
|
||||
Context = typeof(TContext);
|
||||
RepositoryService = typeof(TRepositoryService);
|
||||
RepositoryImplementation = typeof(TRepositoryImplementation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace xDataService.Providers
|
||||
/// Default Guid Key Generator ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
public class XGuidKeyGenerator<TEntity> : IXKeyGenerator<TEntity, Guid>
|
||||
public class XGuidKeyGenerator<TEntity> : XKeyGenerator<TEntity, Guid>, IXKeyGenerator<TEntity, Guid>
|
||||
where TEntity : XBaseEntity<Guid>
|
||||
{
|
||||
private readonly IXSequentialGuid sequentialGuid;
|
||||
@@ -23,7 +23,7 @@ namespace xDataService.Providers
|
||||
this.sequentialGuid = sequentialGuid;
|
||||
}
|
||||
|
||||
public async Task<Guid> GenerateKey(
|
||||
public override async Task<Guid> GenerateKey(
|
||||
IXBaseRepository<TEntity, Guid> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -44,7 +44,7 @@ namespace xDataService.Providers
|
||||
}, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public bool IsEmpty(Guid id)
|
||||
public override bool IsEmpty(Guid id)
|
||||
{
|
||||
//
|
||||
var result = id.IsNull() || id.IsDefaultGuid();
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace xDataService.Providers
|
||||
/// Default Int Key Generator ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
public class XIntKeyGenerator<TEntity> : IXKeyGenerator<TEntity, int>
|
||||
public class XIntKeyGenerator<TEntity> : XKeyGenerator<TEntity, int>, IXKeyGenerator<TEntity, int>
|
||||
where TEntity : XBaseEntity<int>
|
||||
{
|
||||
public async Task<int> GenerateKey(
|
||||
public override async Task<int> GenerateKey(
|
||||
IXBaseRepository<TEntity, int> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -33,7 +33,7 @@ namespace xDataService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool IsEmpty(int id)
|
||||
public override bool IsEmpty(int id)
|
||||
{
|
||||
//
|
||||
var result = id <= 0;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Providers
|
||||
{
|
||||
public abstract class XKeyGenerator<TEntity, TKey> : IXKeyGenerator<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
public abstract Task<TKey> GenerateKey(
|
||||
IXBaseRepository<TEntity, TKey> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public abstract bool IsEmpty(TKey id);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace xDataService.Providers
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
|
||||
public class XStringKeyGenerator<TEntity> : IXKeyGenerator<TEntity, string>
|
||||
public class XStringKeyGenerator<TEntity> : XKeyGenerator<TEntity, string>, IXKeyGenerator<TEntity, string>
|
||||
where TEntity : XBaseEntity<string>
|
||||
{
|
||||
private readonly IXSequentialGuid sequentialGuid;
|
||||
@@ -22,7 +22,7 @@ namespace xDataService.Providers
|
||||
this.sequentialGuid = sequentialGuid;
|
||||
}
|
||||
|
||||
public async Task<string> GenerateKey(
|
||||
public override async Task<string> GenerateKey(
|
||||
IXBaseRepository<TEntity, string> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -41,7 +41,7 @@ namespace xDataService.Providers
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty(string id)
|
||||
public override bool IsEmpty(string id)
|
||||
{
|
||||
return id.IsNullOrEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user