Initial Commit ...
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using GraphQL.Types;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
public interface IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
where TGraph : IGraphType
|
||||
where TGraphKey : IGraphType { }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
public interface IXBaseGraphQLTypeHelper<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey> {
|
||||
string GetInQuerySingleName ();
|
||||
string GetInQueryCollectionName ();
|
||||
|
||||
string GetFindOneName ();
|
||||
|
||||
string GetFindManyName ();
|
||||
|
||||
string GetQueryName ();
|
||||
|
||||
string GetCountName ();
|
||||
|
||||
string GetExistsName ();
|
||||
|
||||
string GetGraphQLPath (string baseGraphPath = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
/// <summary>
|
||||
/// a Base Repository Interface for Manipulate
|
||||
/// an Entity in DataBase
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IXBaseRepository<T, TKey> : IDisposable
|
||||
where T : XBaseEntity<TKey> {
|
||||
//
|
||||
#region Add ...
|
||||
/// <summary>
|
||||
/// add a new Entity ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> AddAsync (
|
||||
T item,
|
||||
bool saveChanges = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// add or update an Entity (add if not exists/update if exists) ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> AddOrUpdateAsync (
|
||||
T item,
|
||||
bool saveChanges = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// add a range of new Entities ...
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task AddRangeAsync (
|
||||
IEnumerable<T> items,
|
||||
bool saveChanges = true
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// remove an Entity by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> RemoveAsync (
|
||||
TKey id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// remove an Entity ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> RemoveAsync (
|
||||
T item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// remove a range of exists Entities ...
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveRangeAsync (
|
||||
IEnumerable<T> items,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve whole items as queryable ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IQueryable<T> AsQueryable ();
|
||||
|
||||
/// <summary>
|
||||
/// retrieve an Entity by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="containsDetail"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> GetAsync (
|
||||
TKey id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
bool containsDetail = false
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Entities ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="containsDetail"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<T>> GetAllAsync (
|
||||
bool ignoreSoftDeleteds = true,
|
||||
bool containsDetail = false
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// find an Entity by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="containsDetail"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> FindOneAsync (
|
||||
Expression<Func<T, bool>> whereClause,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
bool containsDetail = false
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Entities by proving a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="containsDetail"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<T>> FindManyAsync (
|
||||
Expression<Func<T, bool>> whereClause,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
bool containsDetail = false
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Entities based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<T>> QueryAsync (
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<T>> ConditionalQueryAsync (
|
||||
Expression<Func<T, bool>> whereClause,
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Entity values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<T> UpdateAsync (
|
||||
TKey id,
|
||||
T item,
|
||||
bool saveChanges = true
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update a range of Entities ...
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateRangeAsync (
|
||||
IEnumerable<T> items,
|
||||
bool saveChanges = true
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Count ...
|
||||
/// <summary>
|
||||
/// count all exists Entities ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> CountAsync (bool ignoreSoftDeleteds = true);
|
||||
|
||||
/// <summary>
|
||||
/// count all exists Entities Pages by providing page size ...
|
||||
/// </summary>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="totalItems"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> PagesCountAsync (
|
||||
int pageSize,
|
||||
int? totalItems = null
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Exists ...
|
||||
/// <summary>
|
||||
/// Check an Entity exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsExistsAsync (
|
||||
TKey id,
|
||||
bool ignoreSoftDeleteds = true
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Unit Of Work ...
|
||||
/// <summary>
|
||||
/// Save all unsaved Transactions on DbContext ...
|
||||
/// used fo Unit Of Works Design Pattern ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<int> SaveChangesAsync ();
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Key ...
|
||||
TKey GetKey (T item);
|
||||
|
||||
void SetKey (
|
||||
ref T item,
|
||||
TKey id
|
||||
);
|
||||
|
||||
Task<T> HandleKeyAsync (T item);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Detach ...
|
||||
void Detach (T item);
|
||||
|
||||
void Detach (IEnumerable<T> items);
|
||||
|
||||
void Detach (XQueryResult<T> query);
|
||||
|
||||
void Detach (XPageResponse<T> page);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xDataService.Models;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
public interface IXBaseRepositoryEvents<T> {
|
||||
//
|
||||
void AddEvent (XBaseEventModel<T> model);
|
||||
void UpdateEvent (XBaseEventModel<T> model);
|
||||
void RemoveEvent (XBaseEventModel<T> model);
|
||||
|
||||
//
|
||||
void AddManyEvent (XBaseEventModel<IEnumerable<T>> model);
|
||||
void UpdateManyEvent (XBaseEventModel<IEnumerable<T>> model);
|
||||
void RemoveManyEvent (XBaseEventModel<IEnumerable<T>> model);
|
||||
|
||||
//
|
||||
IObservable<XBaseEventModel<T>> OnAddObservable { get; }
|
||||
IObservable<XBaseEventModel<T>> OnUpdateObservable { get; }
|
||||
IObservable<XBaseEventModel<T>> OnRemoveObservable { get; }
|
||||
|
||||
//
|
||||
IObservable<XBaseEventModel<IEnumerable<T>>> OnAddManyObservable { get; }
|
||||
IObservable<XBaseEventModel<IEnumerable<T>>> OnUpdateManyObservable { get; }
|
||||
IObservable<XBaseEventModel<IEnumerable<T>>> OnRemoveManyObservable { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Threading.Tasks;
|
||||
using xDataService.Configuration;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
/// <summary>
|
||||
/// Db Seeder used to seed data on Database on startup time ...
|
||||
/// </summary>
|
||||
public interface IXDbSeeder {
|
||||
IXDbSeederConfig Config { 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 ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
public interface IXKeyGenerator<TEntity, TKey>
|
||||
where TEntity : XBaseEntity<TKey> {
|
||||
bool IsEmpty (TKey id);
|
||||
Task<TKey> GenerateKey (
|
||||
IXBaseRepository<TEntity, TKey> repository
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
/// <summary>
|
||||
/// this service provide Sequential GUID mechanism for Entity Ids ...
|
||||
/// </summary>
|
||||
public interface IXSequentialGuid {
|
||||
Guid GetCurrentGuid ();
|
||||
Guid Next ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using xDataService.Db;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Interfaces {
|
||||
/// <summary>
|
||||
/// Provide Unit Of Works Design Pattern for Db Transactions ...
|
||||
/// Only Used on EFCore ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TDbContext"></typeparam>
|
||||
public interface IXUnitOfWorks<TDbContext> : IDisposable
|
||||
where TDbContext : XDbContext {
|
||||
TDbContext DbContext { get; }
|
||||
DbSet<T> GetDbSet<T, TKey> () where T : XBaseEntity<TKey>;
|
||||
int SaveChanges ();
|
||||
Task<int> SaveChangesAsync ();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user