Add Required Stuffs to running Project on net8.0 ...

This commit is contained in:
2026-04-04 00:11:31 +03:30
parent f863f49af7
commit 058b55f4fa
28 changed files with 1194 additions and 11 deletions
+120
View File
@@ -0,0 +1,120 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using xCommons.Attributes;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xDataService.Interfaces;
using xIdentityService.Controllers;
using xIdentityService.Interfaces;
using xModels.Base;
using xPushService.Base;
using xPushService.Constants;
namespace xAiApi.Base
{
[ApiController]
[ApiVersion("1.0")]
[RequireXPowered(true)]
[Route("api/v{version:apiVersion}/entities/[controller]")]
public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
#region Constructor ...
protected XIBaseV1EntityController(
ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXBaseRepository<TEntity, TKey> repository
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
repository
)
{ }
#endregion
}
public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
#region Props ...
public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
#endregion
//
#region Constructor ...
protected XIBaseV1EntityHubController(
ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXBaseRepository<TEntity, TKey> repository,
IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
repository
)
{
Hub = hub;
}
#endregion
//
#region Hub ...
[NonAction]
public async Task SendPush(
string action,
string payLoad
)
{
//
var actions = new List<string>
{
XBaseEntityHubAction.Add.GetStringValue(),
XBaseEntityHubAction.Update.GetStringValue(),
XBaseEntityHubAction.Delete.GetStringValue(),
XBaseEntityHubAction.AddMany.GetStringValue(),
XBaseEntityHubAction.DeleteMany.GetStringValue(),
XBaseEntityHubAction.UpdateMany.GetStringValue(),
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
};
//
// Validate ...
var isValid =
!Hub.IsNull() &&
!action.IsNullOrEmpty() &&
!payLoad.IsNullOrEmpty() &&
actions.Contains(action);
if (!isValid)
{
return;
}
//
// Retrieve Connection Id ...
var connectionId = GetConnectionId();
var clients = Hub.Clients.All;
if (!connectionId.IsNullOrEmpty())
{
clients = Hub.Clients.AllExcept(connectionId);
}
//
await clients.SendAsync(action, payLoad, connectionId);
}
#endregion
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ namespace xAiApi.Controllers
{
//
var controllerName = GetControllerName();
var message = $"{AppConfiguration.WelcomeMessage}";
var message = $"Salam, {AppConfiguration.WelcomeMessage}";
//
return Ok(message);
+326
View File
@@ -0,0 +1,326 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using xAiApi.Base;
using xAiApi.Data.Interfaces;
using xAiApi.Data.Models.Entities;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xIdentityHelper;
using xIdentityService.Interfaces;
using xModels.Base;
using xModels.Dtos;
using xPushService.Base;
using xPushService.Constants;
namespace xAiApi.Controllers.V1.Entities
{
/// <summary>
/// Simple XTest Entity Controller ...
/// </summary>
public class TestsController : XIBaseV1EntityHubController<XTest, int>
{
//
#region Constructor ...
public TestsController(
ILogger<TestsController> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXTestRepository repository,
IHubContext<XBaseEntityHub<XTest, int>> hub = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
repository,
hub
)
{ }
#endregion
//
#region Interface Implementations ...
//
#region Retrieve ...
[HttpGet("{id}")]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<XTest>> Get(
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
)
{
return await base
.Get(
id: id,
containsDetail: containsDetail,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
[HttpGet]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<IEnumerable<XTest>>> GetAll(
[FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
)
{
return await base
.GetAll(
containsDetail: containsDetail,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
[HttpGet("FindOne/{query}")]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<XTest>> FindOne(
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
)
{
return await base
.FindOne(
query: query,
containsDetail: containsDetail,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
[HttpGet("FindMany/{query}")]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<IEnumerable<XTest>>> FindMany(
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
)
{
return await base
.FindMany(
query: query,
containsDetail: containsDetail,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
[HttpGet("Query")]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<XQueryResult<XTest>>> Query(
[FromQuery] XQuery query, [FromQuery] bool ignoreSoftDeleteds = true
)
{
return await base
.Query(
query: query,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
#endregion
//
#region Add ...
[HttpPost]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult<XTest>> Add(
[FromBody] XTest item
)
{
//
var entity = await base
.Add(item);
//
// Handle Sending Push Notification ...
if (!entity.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Add.GetStringValue(),
payLoad: entity.ToJSON()
);
}
//
return entity;
}
[HttpPost("AddOrUpdate")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult<XTest>> AddOrUpdate(
[FromBody] XTest item
)
{
//
var entity = await base
.AddOrUpdate(item);
//
// Handle Sending Push Notification ...
if (!entity.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
payLoad: entity.ToJSON()
);
}
//
return entity;
}
[HttpPost("AddMany")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult> AddMany(
[FromBody] XBaseRangeRequest<XTest> request
)
{
//
var result = await base
.AddMany(request);
//
if (!(result as OkObjectResult).IsNull())
{
//
await SendPush(
action: XBaseEntityHubAction.AddMany.GetStringValue(),
payLoad: request.Items.ToJSON()
);
}
//
return result;
}
#endregion
//
#region Update ...
[HttpPut("{id}")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult<XTest>> Update(
[FromRoute] int id, [FromBody] XTest item
)
{
//
var entity = await base
.Update(
id,
item
);
//
if (!entity.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Update.GetStringValue(),
payLoad: entity.ToJSON()
);
}
//
return entity;
}
[HttpPost("UpdateMany")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult<bool>> UpdateMany(
[FromBody] XBaseRangeRequest<XTest> request
)
{
//
var result = await base
.UpdateMany(request);
//
var resultObject = (result.Result as OkObjectResult).Value;
if (!resultObject.IsNull() && (bool)resultObject)
{
//
await SendPush(
action: XBaseEntityHubAction.UpdateMany.GetStringValue(),
payLoad: request.Items.ToJSON()
);
}
//
return result;
}
#endregion
//
#region Exists ...
[HttpGet("{id}/IsExists")]
[Authorize(Policy = XPolicies.EnabledUser)]
public override async Task<ActionResult<bool>> IsExists(
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true
)
{
return await base
.IsExists(
id: id,
ignoreSoftDeleteds: ignoreSoftDeleteds
);
}
#endregion
//
#region Remove ...
[HttpDelete("{id}")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult<XTest>> Remove(
[FromRoute] int id, bool softDelete = true
)
{
//
var entity = await base
.Remove(
id: id,
softDelete: softDelete
);
//
if (!entity.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Delete.GetStringValue(),
payLoad: entity.ToJSON()
);
}
//
return entity;
}
[HttpPost("RemoveMany")]
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
public override async Task<ActionResult> RemoveMany(
[FromBody] XBaseRangeRequest<XTest> request, bool softDelete = true
)
{
//
var result = await base
.RemoveMany(
request: request,
softDelete: softDelete
);
//
if (!(result as OkObjectResult).IsNull())
{
//
await SendPush(
action: XBaseEntityHubAction.DeleteMany.GetStringValue(),
payLoad: request.Items.ToJSON()
);
}
//
return result;
}
#endregion
#endregion
}
}
@@ -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; }
}
}
+7
View File
@@ -0,0 +1,7 @@
namespace xAiApi.Data.Constants
{
public partial struct ConfigurationNodeNames
{
public const string DATA_SERVICE_DB_SEED_NODE = "DbSeeder";
}
}
+9
View File
@@ -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);
}
}
}
+25
View File
@@ -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";
}
}
}
+22
View File
@@ -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
)
{ }
}
}
+13
View File
@@ -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));
}
}
}
+13
View File
@@ -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>();
}
}
}
}
+199
View File
@@ -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
}
}
+7
View File
@@ -0,0 +1,7 @@
using xDataService.Interfaces;
namespace xAiApi.Data.Interfaces
{
public interface IXAiApiDbSeederConfig : IXDbSeederConfig
{ }
}
+8
View File
@@ -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>
{ }
}
+8
View File
@@ -0,0 +1,8 @@
using xAiApi.Data.Models.Entities;
using xDataService.Interfaces;
namespace xAiApi.Data.Interfaces
{
public interface IXTestRepository : IXBaseRepository<XTest, int>
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using xModels.Base;
namespace xAiApi.Data.Models.Entities
{
public class XTest : XBaseIntIDEntity
{
public string Title { get; set; }
}
}
+7
View File
@@ -0,0 +1,7 @@
namespace xAiApi.Data.Models
{
public class XTestDescriptor
{
public string Title { get; set; }
}
}
+37
View File
@@ -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
}
}
+64
View File
@@ -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
}
}
+28
View File
@@ -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) { }
}
}
View File
+80 -6
View File
@@ -24,6 +24,9 @@ using xDataService.Interfaces;
using xPushService.Helpers;
using xAiApi.Extensions;
using xAiApi.DI;
using xAiApi.Data.Helpers;
using xAiApi.Data;
using xAiApi.Data.Seeder;
// using xApi.Extensions;
// using xDataHelper;
// using xDataHelper.DbSeeder;
@@ -123,6 +126,81 @@ namespace xAiApi
//
// Register XIdentityService ...
services.AddXIdentityService(Configuration, lifeTime);
//
// Register DataService here ...
#region Register xDataService ...
//
// Register IXDataServiceHelper ...
services.AddSingleton<IXDataServiceHelper, XAiApiDataProviderHelper>();
//
// Prepare Db Options Builder based on Provider ...
var providerType = Configuration.GetXDbProviderType();
switch (providerType)
{
//
case XDbProviders.MySQL:
case XDbProviders.SQLite:
case XDbProviders.SQLServer:
Action<dynamic> optionsBuilder = optionsBuilder = b =>
{
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
};
//
// Register xDataService on DI ...
services.AddXDataService<XAiApiDbContext, XAiApiDbSeeder>(
Configuration,
lifeTime,
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME,
optionsBuilder
);
break;
//
case XDbProviders.MongoDB:
//
// Register xDataService on DI ...
services.AddXDataService<XAiApiDbSeeder>(
Configuration,
lifeTime,
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME
);
break;
}
#endregion
//
// Register GraphQL here ...
#region Register xGraphQL ...
//
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
//
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
//
// Register XGraphQL Helper ...
services.AddSingleton<IXGraphQLHelper, XAiApiDataHelperGraphQLHelper>();
//
services.AddXGraphQL(options =>
{
//
options.EnableMetrics = true;
options.UnhandledExceptionDelegate = context =>
{
Console.WriteLine("XGraphQL Error: " + context.OriginalException.Message);
};
});
#endregion
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
@@ -166,7 +244,7 @@ namespace xAiApi
//
#region XPushService ...
//
var helper = new XPushServiceHelper();
// var helper = new XPushServiceHelper();
//
// helper.AddHub<XTermsHub>("termsHub");
@@ -175,17 +253,13 @@ namespace xAiApi
// helper.AddHub<XStringEntityHub>("stringEntityHub");
//
app.UseXPushService(helper);
// app.UseXPushService(helper);
#endregion
//
// Use xDataService Middleware ...
app.UseXDataService();
// //
// // Using Services ...
// app.UseXServices();
//
// Use xGraphQL Middleware ...
app.UseXGraphQL(withPlayground: withPlayground);
+1 -1
View File
@@ -13,7 +13,7 @@
"SwaggerConfiguration": {
"Version": "v1.0",
"Title": "xSaherElm AI API",
"Description": "Complete API Documentation",
"Description": "Complete AI API Documentation",
"Contact": {
"Name": "Hadi Khazaee Asl",
"Email": "hadi_khazaee_asl@yahoo.com",
+15 -2
View File
@@ -1,8 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="megan" value="https://hub.megan.ir/nuget/index.json" />
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
<add key="RunFlare" value="https://mirror-nuget.runflare.com/v3/index.json" protocolVersion="3" />
<!-- <add key="NugetIran" value="https://repo.nugetiran.ir/repository/nuget-group/" /> -->
<!-- <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> -->
<!-- <add key="RunFlare" value="https://mirror-nuget.runflare.com/v3/index.json" protocolVersion="3" /> -->
<!-- <add key="jfrog" value="https://jfrog.rpk.ir/artifactory/api/nuget/v3/nuget-rpk-virtual" disableTLSCertificateValidation="true" /> -->
</packageSources>
<packageSourceCredentials>
<!-- Credentials for other repositories (if needed) -->
<!-- <jfrog>
<add key="Username" value="admin" />
<add key="ClearTextPassword" value="Aliz@123" />
</jfrog> -->
</packageSourceCredentials>
<!-- <config>
<add key="signatureValidationMode" value="accept" />
</config> -->
</configuration>
+2 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<!-- Runtime Definition -->
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageId>xSaherElm.xAiApi</PackageId>
<Version>1.0.0</Version>
<Authors>Hadi Khazaee Asl</Authors>
@@ -29,6 +29,7 @@
<!-- Dependencies -->
<ItemGroup>
<!-- <PackageReference Include="Microsoft.SemanticKernel" Version="1.14.1" /> -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.11" />
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="5.0.0" />