last ...
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MongoDB.Bson.Serialization.Conventions;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Constants;
|
||||
using xDataService.Db;
|
||||
using xDataService.DI;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xDataService.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Data Base Descriptor ...
|
||||
/// </summary>
|
||||
public abstract class XDatabaseDescriptor : IXDatabaseDescriptor
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
/// <summary>
|
||||
/// Database Name ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Database Provider ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual XDbProviders Provider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Db Context...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual Type Context { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Database Connecion String ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual string ConnectionString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Data Service Configuration ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual XDataBaseConfiguration Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Repositories Descriptions ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual IList<XRepositoryDescriptor> Repositories { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Mongo Convention Packs ...
|
||||
/// </summary>
|
||||
public ConventionPack ConventionPacks { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// DbContext Options Builder ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Action<dynamic> OptionsBuilder { get; set; } = null;
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
/// <summary>
|
||||
/// Constructor of Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="repositories"></param>
|
||||
public XDatabaseDescriptor(
|
||||
string name,
|
||||
IList<XRepositoryDescriptor> repositories = null
|
||||
)
|
||||
{
|
||||
//
|
||||
Name = name;
|
||||
Repositories = repositories;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Configure ...
|
||||
/// <summary>
|
||||
/// Configure Database Descriptor using Registered Services ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public void Configure(
|
||||
IServiceCollection services
|
||||
)
|
||||
{
|
||||
//
|
||||
bool isValid = !Name.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var xDataServiceConfiguration = services.GetRegisteredService<XDataServiceConfiguration>();
|
||||
isValid =
|
||||
!xDataServiceConfiguration.IsNullOrDefault() &&
|
||||
xDataServiceConfiguration.Databases.HasChild() &&
|
||||
xDataServiceConfiguration.Databases.Keys.Any(k => k == Name);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var database = xDataServiceConfiguration.Databases[Name];
|
||||
isValid = !database.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Configure(database);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Database Descriptor using IConfiguration ...
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public void Configure(
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
bool isValid = !Name.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var xDataServiceConfiguration = configuration.GetXDataServiceConfiguration();
|
||||
isValid =
|
||||
!xDataServiceConfiguration.IsNullOrDefault() &&
|
||||
xDataServiceConfiguration.Databases.HasChild() &&
|
||||
xDataServiceConfiguration.Databases.Keys.Any(k => k == Name);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var database = xDataServiceConfiguration.Databases[Name];
|
||||
isValid = !database.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Configure(database);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Database Descriptor using Database Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public void Configure(
|
||||
XDataBaseConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
Configuration = configuration;
|
||||
Provider = configuration.Provider;
|
||||
ConnectionString = configuration.ConnectionString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Database Descriptor using Provider and Connection String ...
|
||||
/// </summary>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="connectionString"></param>
|
||||
public void Configure(
|
||||
XDbProviders provider,
|
||||
string connectionString
|
||||
)
|
||||
{
|
||||
//
|
||||
Provider = provider;
|
||||
ConnectionString = connectionString;
|
||||
Configuration = new XDataBaseConfiguration
|
||||
{
|
||||
Provider = provider,
|
||||
ConnectionString = connectionString
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data Base Descriptor ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TContext"></typeparam>
|
||||
public abstract class XDatabaseDescriptor<TContext> : XDatabaseDescriptor, IXDatabaseDescriptor<TContext>
|
||||
where TContext : XDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor of Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="repositories"></param>
|
||||
public XDatabaseDescriptor(
|
||||
string name,
|
||||
IList<XRepositoryDescriptor> repositories = null
|
||||
) : base(
|
||||
name: name,
|
||||
repositories: repositories
|
||||
)
|
||||
{
|
||||
Context = typeof(TContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using GraphQL.Types;
|
||||
using xDataService.GraphQL;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// a Global non Generic Repository Descriptor ...
|
||||
/// </summary>
|
||||
public class XRepositoryDescriptor { }
|
||||
|
||||
/// <summary>
|
||||
/// a Repository Descriptor ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class XRepositoryDescriptor<TEntity, TKey> : XRepositoryDescriptor
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity Type GraphQL Schema ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Schema GraphSchema { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type Helper ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseGraphQLTypeHelper GraphTypeHelper { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GrapQL Query ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseGraphQLQuery<TEntity, TKey> GraphQuery { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Entity GraphQL Type ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public XBaseGraphObjectType<TEntity, TKey> GraphType { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Event Provider ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseRepositoryEvents<TEntity> Events { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Key Generator for Entity ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXKeyGenerator<TEntity, TKey> KeyGenerator { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Repository Data Access Design Pattern ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public IXBaseRepository<TEntity, TKey> Repository { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user