Add Required Stuffs to running Project on net8.0 ...
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Configurations
|
||||
{
|
||||
public class XAiApiDbSeederConfig : IXAiApiDbSeederConfig, IXDbSeederConfig
|
||||
{
|
||||
public bool UpdateExists { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace xAiApi.Data.Constants
|
||||
{
|
||||
public partial struct ConfigurationNodeNames
|
||||
{
|
||||
public const string DATA_SERVICE_DB_SEED_NODE = "DbSeeder";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Events;
|
||||
|
||||
namespace xAiApi.Data.Events
|
||||
{
|
||||
public class XTestEvents : XBaseRepositoryEvents<XTest>, IXTestEvents
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xAiApi.Data.Configurations;
|
||||
using xAiApi.Data.Constants;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xCommons.Extensions;
|
||||
|
||||
namespace xAiApi.Data.Extensions
|
||||
{
|
||||
public static class XAiApiDbSeederExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Extract XDbSeeder Configurations From IConfiguration
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public static XAiApiDbSeederConfig GetXDbSeederConfiguration(
|
||||
this IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var xDbSeederConfigSection = configuration.GetSection(ConfigurationNodeNames.DATA_SERVICE_DB_SEED_NODE);
|
||||
return xDbSeederConfigSection.Get<XAiApiDbSeederConfig>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register XDbSeeder Configurations on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXDbSeederConfiguration(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var dbSeederConfig = configuration.GetXDbSeederConfiguration();
|
||||
if (dbSeederConfig.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
services.AddSingleton<IXAiApiDbSeederConfig>(dbSeederConfig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register XDbSeeder Configurations on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXDbSeederConfiguration(
|
||||
this IServiceCollection services,
|
||||
XAiApiDbSeederConfig configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
services.AddSingleton<IXAiApiDbSeederConfig>(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
|
||||
namespace xAiApi.Data.GraphQL
|
||||
{
|
||||
public class XTestGraphQLTypeHelper : XBaseGraphQLTypeHelper<XTest, int>, IXTestGraphQLTypeHelper
|
||||
{
|
||||
public XTestGraphQLTypeHelper(
|
||||
XDataServiceConfiguration configuration
|
||||
) : base(configuration)
|
||||
{ }
|
||||
|
||||
public override string GetInQueryCollectionName()
|
||||
{
|
||||
return "tests";
|
||||
}
|
||||
|
||||
public override string GetInQuerySingleName()
|
||||
{
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using GraphQL.Types;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
|
||||
namespace xAiApi.Data.GraphQL
|
||||
{
|
||||
public class XTestGraphQuery : XBaseGraphQLQuery<XTest, int, XTestGraphType, IntGraphType>
|
||||
{
|
||||
public XTestGraphQuery(
|
||||
XDataServiceConfiguration configuration,
|
||||
IXTestRepository repository,
|
||||
IXTestGraphQLTypeHelper helper
|
||||
) : base(
|
||||
configuration,
|
||||
repository,
|
||||
helper
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using GraphQL.Types;
|
||||
|
||||
namespace xAiApi.Data.GraphQL
|
||||
{
|
||||
public class XTestGraphSchema : Schema
|
||||
{
|
||||
public XTestGraphSchema(IServiceProvider services) : base(services)
|
||||
{
|
||||
Query = (XTestGraphQuery)services.GetService(typeof(XTestGraphQuery));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.GraphQL;
|
||||
|
||||
namespace xAiApi.Data.GraphQL
|
||||
{
|
||||
public class XTestGraphType : XBaseGraphObjectType<XTest, int>
|
||||
{
|
||||
public XTestGraphType() : base()
|
||||
{
|
||||
Field(x => x.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using GraphQL.Server;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xAiApi.Data.GraphQL;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Helpers
|
||||
{
|
||||
public class XAiApiDataHelperGraphQLHelper : IXGraphQLHelper
|
||||
{
|
||||
public void AddXGraphEnumTypes(IServiceCollection services) { }
|
||||
|
||||
public void AddXGraphInputTypes(IServiceCollection services) { }
|
||||
|
||||
public void AddXGraphMutations(IServiceCollection services) { }
|
||||
|
||||
public void AddXGraphObjectTypes(IServiceCollection services)
|
||||
{
|
||||
//
|
||||
// XTest ...
|
||||
services.AddSingleton<XTestGraphType>();
|
||||
services.AddSingleton<XBaseGraphQLEventType<XTest, int, XTestGraphType>>();
|
||||
}
|
||||
|
||||
public void AddXGraphQueries(IServiceCollection services)
|
||||
{
|
||||
//
|
||||
// XTest ...
|
||||
services.AddSingleton<IXTestGraphQLTypeHelper, XTestGraphQLTypeHelper>();
|
||||
services.AddScoped<XTestGraphQuery>();
|
||||
}
|
||||
|
||||
public void AddXGraphSchemas(IServiceCollection services)
|
||||
{
|
||||
//
|
||||
services.AddScoped<XTestGraphSchema>();
|
||||
}
|
||||
|
||||
public void AddXGraphSubscriptions(IServiceCollection services) { }
|
||||
|
||||
public IGraphQLBuilder AddXGraphTypes(IGraphQLBuilder builder)
|
||||
{
|
||||
//
|
||||
builder.AddGraphTypes(typeof(XTestGraphSchema));
|
||||
|
||||
//
|
||||
return builder;
|
||||
}
|
||||
|
||||
public void UseXGraph(IApplicationBuilder app)
|
||||
{
|
||||
//
|
||||
using (var scope = app.ApplicationServices.CreateScope())
|
||||
{
|
||||
//
|
||||
// XDataServiceConfiguration ...
|
||||
var dataServiceConfiguration = scope.ServiceProvider.GetService<XDataServiceConfiguration>();
|
||||
|
||||
//
|
||||
// XTest ...
|
||||
var testHelper = scope.ServiceProvider.GetService<IXTestGraphQLTypeHelper>();
|
||||
app.UseGraphQL<XTestGraphSchema>(testHelper.GetGraphQLPath());
|
||||
app.UseGraphQLWebSockets<XTestGraphSchema>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Bson.Serialization.Conventions;
|
||||
using xAiApi.Data.Events;
|
||||
using xAiApi.Data.Extensions;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xAiApi.Data.Repositories.Ef;
|
||||
using xAiApi.Data.Repositories.Mongo;
|
||||
using xAiApi.Data.Seeder;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Constants;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xExceptions.Constants;
|
||||
|
||||
namespace xAiApi.Data.Helpers
|
||||
{
|
||||
public class XAiApiDataProviderHelper : IXDataServiceHelper
|
||||
{
|
||||
//
|
||||
private readonly ILogger<XAiApiDataProviderHelper> logger;
|
||||
|
||||
//
|
||||
public XAiApiDataProviderHelper(ILogger<XAiApiDataProviderHelper> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
public void AddDbContext(
|
||||
IServiceCollection services,
|
||||
string connectionString,
|
||||
XDbProviders dbProvider,
|
||||
ServiceLifetime lifetime,
|
||||
Action<dynamic> optionsBuilder = null
|
||||
)
|
||||
{
|
||||
//
|
||||
logger.LogInformation("Start AddDbContext ...");
|
||||
|
||||
//
|
||||
switch (dbProvider)
|
||||
{
|
||||
//
|
||||
case XDbProviders.MySQL:
|
||||
//
|
||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
||||
{
|
||||
cfg.UseMySQL(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
case XDbProviders.SQLite:
|
||||
//
|
||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
||||
{
|
||||
cfg.UseSqlite(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
case XDbProviders.SQLServer:
|
||||
//
|
||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
||||
{
|
||||
cfg.UseSqlServer(connectionString, optionsBuilder);
|
||||
}, lifetime);
|
||||
break;
|
||||
|
||||
//
|
||||
case XDbProviders.MongoDB:
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
Console.WriteLine("Unsuported Data Provider Type ...");
|
||||
XException.NotAllowed.Throw();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
logger.LogInformation("End AddDbContext ...");
|
||||
}
|
||||
|
||||
public void AddRepositories(
|
||||
IServiceCollection services,
|
||||
ServiceLifetime lifetime
|
||||
)
|
||||
{
|
||||
//
|
||||
logger.LogInformation("Start AddRepositories ...");
|
||||
|
||||
//
|
||||
var dataServiceConfiguration = services.GetRegisteredService<XDataServiceConfiguration>();
|
||||
|
||||
//
|
||||
#region Events ...
|
||||
//
|
||||
// XTest ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXTestEvents), typeof(XTestEvents), ServiceLifetime.Singleton));
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Repositories ...
|
||||
//
|
||||
// Adding DbContext if EFCore ...
|
||||
switch (dataServiceConfiguration.Provider)
|
||||
{
|
||||
//
|
||||
case XDbProviders.MySQL:
|
||||
case XDbProviders.SQLite:
|
||||
case XDbProviders.SQLServer:
|
||||
//
|
||||
// XTest ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXTestRepository), typeof(XTestEfRepository<XAiApiDbContext>), lifetime));
|
||||
break;
|
||||
|
||||
//
|
||||
case XDbProviders.MongoDB:
|
||||
//
|
||||
// XTest ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXTestRepository), typeof(XTestMongoRepository), lifetime));
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
Console.WriteLine("Unsuported Data Provider Type ...");
|
||||
XException.NotAllowed.Throw();
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
logger.LogInformation("End AddRepositories ...");
|
||||
}
|
||||
|
||||
public void AddKeyGenerators(IServiceCollection services)
|
||||
{
|
||||
//
|
||||
services.AddSingleton<IXKeyGenerator<XTest, int>, XIntKeyGenerator<XTest>>();
|
||||
}
|
||||
|
||||
public void AddDbSeederConfiguration(
|
||||
IServiceCollection services,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
logger.LogInformation("Start AddDbSeederConfiguration ...");
|
||||
|
||||
//
|
||||
// Retrieve Config from appSettings ...
|
||||
var dbSeederConfig = configuration.GetXDbSeederConfiguration();
|
||||
if (!dbSeederConfig.IsNull())
|
||||
{
|
||||
services.AddXDbSeederConfiguration(dbSeederConfig);
|
||||
}
|
||||
|
||||
//
|
||||
logger.LogInformation("End AddDbSeederConfiguration ...");
|
||||
}
|
||||
|
||||
public void AddDbSeeder<TDbSeeder>(
|
||||
IServiceCollection services,
|
||||
IConfiguration config,
|
||||
ServiceLifetime lifetime
|
||||
) where TDbSeeder : IXDbSeeder
|
||||
{
|
||||
//
|
||||
logger.LogInformation("Start AddDbSeeder ...");
|
||||
|
||||
//
|
||||
// Adding DbSeeder ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXDbSeeder), typeof(XAiApiDbSeeder), lifetime));
|
||||
|
||||
//
|
||||
logger.LogInformation("End AddDbSeeder ...");
|
||||
}
|
||||
|
||||
public ConventionPack MongoConventionPacks()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RegisterMongoExtras() { }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Interfaces
|
||||
{
|
||||
public interface IXAiApiDbSeederConfig : IXDbSeederConfig
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Interfaces
|
||||
{
|
||||
public interface IXTestEvents : IXBaseRepositoryEvents<XTest>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Interfaces
|
||||
{
|
||||
public interface IXTestGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XTest, int>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Interfaces
|
||||
{
|
||||
public interface IXTestRepository : IXBaseRepository<XTest, int>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xModels.Base;
|
||||
|
||||
namespace xAiApi.Data.Models.Entities
|
||||
{
|
||||
public class XTest : XBaseIntIDEntity
|
||||
{
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace xAiApi.Data.Models
|
||||
{
|
||||
public class XTestDescriptor
|
||||
{
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Linq;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Db;
|
||||
using xDataService.EFRepositories;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Repositories.Ef
|
||||
{
|
||||
public class XTestEfRepository<TDbContext> : XBaseEFRepository<XTest, int, XAiApiDbContext>, IXTestRepository
|
||||
where TDbContext : XDbContext
|
||||
{
|
||||
//
|
||||
public XTestEfRepository(
|
||||
IXUnitOfWorks<XAiApiDbContext> unitOfWorks,
|
||||
XDataServiceConfiguration configuration,
|
||||
IXKeyGenerator<XTest, int> keyGenerator = null,
|
||||
IXBaseRepositoryEvents<XTest> baseRepositoryEvents = null
|
||||
) : base(
|
||||
unitOfWorks,
|
||||
configuration,
|
||||
keyGenerator,
|
||||
baseRepositoryEvents
|
||||
)
|
||||
{ }
|
||||
|
||||
public override IQueryable<XTest> GetFullDbSet()
|
||||
{
|
||||
return dbSet;
|
||||
}
|
||||
|
||||
//
|
||||
#region Special ...
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.MongoRepositories;
|
||||
|
||||
namespace xAiApi.Data.Repositories.Mongo
|
||||
{
|
||||
public class XTestMongoRepository : XBaseMongoRepository<XTest, int>, IXTestRepository
|
||||
{
|
||||
//
|
||||
public XTestMongoRepository(
|
||||
XDataServiceConfiguration configuration,
|
||||
string collectionName = null,
|
||||
IXKeyGenerator<XTest, int> keyGenerator = null,
|
||||
IXBaseRepositoryEvents<XTest> baseRepositoryEvents = null
|
||||
) : base(
|
||||
configuration,
|
||||
collectionName,
|
||||
keyGenerator,
|
||||
baseRepositoryEvents
|
||||
)
|
||||
{ }
|
||||
|
||||
public override IMongoQueryable<XTest> GetFullDbSet()
|
||||
{
|
||||
return collection
|
||||
.AsQueryable();
|
||||
}
|
||||
|
||||
//
|
||||
#region Special ...
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
namespace xAiApi.Data.Seeder
|
||||
{
|
||||
public class XAiApiDbSeeder : IXDbSeeder
|
||||
{
|
||||
//
|
||||
public IXDbSeederConfig Config { get; }
|
||||
public readonly IXAiApiDbSeederConfig config;
|
||||
private readonly ILogger<XAiApiDbSeeder> logger;
|
||||
private readonly IXTestRepository testsRepository;
|
||||
public XDataServiceConfiguration DataServiceConfiguration { get; }
|
||||
|
||||
//
|
||||
public XAiApiDbSeeder(
|
||||
ILogger<XAiApiDbSeeder> logger,
|
||||
IXTestRepository testsRepository,
|
||||
IXAiApiDbSeederConfig config = null,
|
||||
XDataServiceConfiguration dataServiceConfiguration = null
|
||||
)
|
||||
{
|
||||
Config = config;
|
||||
this.config = config;
|
||||
this.logger = logger;
|
||||
this.testsRepository = testsRepository;
|
||||
DataServiceConfiguration = dataServiceConfiguration;
|
||||
}
|
||||
|
||||
public async Task Seed()
|
||||
{
|
||||
//
|
||||
// TODO: Do any additional Seeding ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Check Configuration Exists ...
|
||||
if (config.IsNull())
|
||||
{
|
||||
logger.LogInformation($"there is no Configured Objects to Seed ...");
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"Failed Seeding: {ex.Message} ...");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
private async Task SeedTest(XTestDescriptor dTests)
|
||||
{ }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Db;
|
||||
|
||||
namespace xAiApi.Data
|
||||
{
|
||||
public partial class XAiApiDbContext : XDbContext
|
||||
{
|
||||
//
|
||||
#region DbSets ...
|
||||
public DbSet<XTest> Tests { get; set; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Navigation Property Entities ...
|
||||
#endregion
|
||||
|
||||
public XAiApiDbContext(
|
||||
DbContextOptions options,
|
||||
XDataServiceConfiguration config
|
||||
) : base(options, config) { }
|
||||
|
||||
public override void OnXConfiguring(DbContextOptionsBuilder optionsBuilder) { }
|
||||
|
||||
public override void OnXModelCreating(ModelBuilder modelBuilder) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user