add support for Db Seeder, Fix GraphQL Generic Usage ...
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user