358 lines
11 KiB
C#
358 lines
11 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using xCategoryService.DI;
|
|
using xCommons.Extensions;
|
|
using xDataService.DI;
|
|
using xDataService.Models;
|
|
using xFileService.DI;
|
|
using xIdentityService.DI;
|
|
using xMessageService.DI;
|
|
using xPushService.DI;
|
|
using xPushService.Helpers;
|
|
using xServices.Configurations;
|
|
using xServices.Constants;
|
|
using xServices.Databases;
|
|
using xServices.Interfaces;
|
|
using xServices.Providers;
|
|
using xStorageService.DI;
|
|
using xStringService.DI;
|
|
using xTagService.DI;
|
|
using xTermsAndConditionsService.DI;
|
|
using xWebinarService.DI;
|
|
|
|
namespace xServices.DI
|
|
{
|
|
public static partial class XDIHelperExtension
|
|
{
|
|
/// <summary>
|
|
/// Retrive Services Configurations ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static XServicesConfiguration GetXServicesConfiguration(
|
|
this IConfiguration source
|
|
)
|
|
{
|
|
//
|
|
var xConfig = source
|
|
.GetSection(ConfigurationNodeNames.SERVICES_NODE);
|
|
var result = xConfig.Get<XServicesConfiguration>();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service Configuration ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="configuration"></param>
|
|
public static void AddXServicesConfiguration(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration
|
|
)
|
|
{
|
|
//
|
|
var config = configuration
|
|
.GetXServicesConfiguration();
|
|
if (config.IsNull())
|
|
{
|
|
config = new XServicesConfiguration();
|
|
}
|
|
|
|
//
|
|
services.AddSingleton(config);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Service Configuration ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="configuration"></param>
|
|
public static void AddXServicesConfiguration(
|
|
this IServiceCollection services,
|
|
XServicesConfiguration configuration
|
|
)
|
|
{
|
|
//
|
|
if (configuration.IsNull())
|
|
{
|
|
configuration = new XServicesConfiguration();
|
|
}
|
|
|
|
//
|
|
services.AddSingleton(configuration);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Services ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="databases"></param>
|
|
/// <param name="lifeTime"></param>
|
|
public static void AddXServices(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
IEnumerable<XDatabaseDescriptor> databases = null,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
)
|
|
{
|
|
//
|
|
var config = configuration.GetXServicesConfiguration();
|
|
|
|
//
|
|
AddServices(
|
|
config: config,
|
|
services: services,
|
|
lifeTime: lifeTime,
|
|
databases: databases,
|
|
configuration: configuration
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Services ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="config"></param>
|
|
/// <param name="databases"></param>
|
|
/// <param name="lifeTime"></param>
|
|
public static void AddXServices(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
XServicesConfiguration config,
|
|
IEnumerable<XDatabaseDescriptor> databases = null,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
)
|
|
{
|
|
//
|
|
AddServices(
|
|
config: config,
|
|
services: services,
|
|
lifeTime: lifeTime,
|
|
databases: databases,
|
|
configuration: configuration
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use All Required Middlewares ...
|
|
/// </summary>
|
|
/// <param name="app"></param>
|
|
/// <param name="databases"></param>
|
|
/// <param name="isDevelopmentEnvironment"></param>
|
|
public static void UseXServices(
|
|
this IApplicationBuilder app,
|
|
IEnumerable<XDatabaseDescriptor> databases = null,
|
|
bool isDevelopmentEnvironment = false
|
|
)
|
|
{
|
|
//
|
|
// Use Storage Service ...
|
|
app.UseXStorageService();
|
|
|
|
//
|
|
#region Use Data Data Service ...
|
|
if (databases.HasChild())
|
|
{
|
|
//
|
|
databases
|
|
.ToList()
|
|
.ForEach(database =>
|
|
{
|
|
//
|
|
app.UseXDatabase(
|
|
descriptor: database,
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
});
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Use Hubs ...
|
|
//
|
|
var pushHelper = new XPushServiceHelper();
|
|
|
|
//
|
|
pushHelper.AddHub<XTestDtoHub>("testDto");
|
|
pushHelper.AddHub<XTestEntityHub>("testEntity");
|
|
|
|
//
|
|
app.UseXPushService(pushHelper);
|
|
#endregion
|
|
|
|
//
|
|
// Using String Service ...
|
|
app.UseXStringService(
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
|
|
//
|
|
// Using Terms and Conditions Service ...
|
|
app.UseXTermsAndConditionsService();
|
|
|
|
//
|
|
// Using Tag Service ...
|
|
app.UseXTagService(
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
|
|
//
|
|
// Using File Service ...
|
|
app.UseXFileService(
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
|
|
//
|
|
// Using Category Service ...
|
|
app.UseXCategoryService(
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
|
|
//
|
|
// Using XWebinar Service ...
|
|
app.UsexWebinarService(
|
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
|
);
|
|
}
|
|
|
|
//
|
|
#region Private ...
|
|
/// <summary>
|
|
/// Register Required Services ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="config"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="databases"></param>
|
|
/// <param name="lifeTime"></param>
|
|
private static void AddServices(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
XServicesConfiguration config = null,
|
|
IEnumerable<XDatabaseDescriptor> databases = null,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
)
|
|
{
|
|
//
|
|
// Check config ...
|
|
if (config.IsNull())
|
|
{
|
|
config = new XServicesConfiguration();
|
|
}
|
|
|
|
//
|
|
// Storage Service ...
|
|
services.AddXStorageService(configuration);
|
|
|
|
//
|
|
// Message Service ...
|
|
services.AddXMessageService(config: configuration);
|
|
|
|
//
|
|
#region Register Identity Service ...
|
|
services.AddXIdentityService(
|
|
configuration: configuration,
|
|
lifeTime: ServiceLifetime.Scoped
|
|
);
|
|
#endregion
|
|
|
|
//
|
|
#region Register Data Service ...
|
|
//
|
|
if (databases.HasChild())
|
|
{
|
|
//
|
|
databases
|
|
.ToList()
|
|
.ForEach(database =>
|
|
{
|
|
//
|
|
// Register DataBase ...
|
|
services.AddXDatabase(
|
|
lifeTime: lifeTime,
|
|
descriptor: database,
|
|
configuration: configuration
|
|
);
|
|
});
|
|
}
|
|
|
|
//
|
|
// Register Repository Services ...
|
|
services.AddScoped<IXTestProvider, XTestProvider>();
|
|
services.AddScoped<IXTestRepositoryService, XTestRepositoryService>();
|
|
#endregion
|
|
|
|
//
|
|
#region Register Push Service ...
|
|
//
|
|
// Push Service ...
|
|
services.AddXPushService(
|
|
config: configuration,
|
|
lifeTime: ServiceLifetime.Scoped
|
|
);
|
|
|
|
//
|
|
// Register Provider Services ...
|
|
// since Hubs required Identity Provider, you Have to Register IdentityService as Requirements ...
|
|
// a Provider Service, Provides Repository (Entity) or Service (Dto) based
|
|
// Data Manipulation Actions by Supporting Hub Contexts Events ...
|
|
services.AddScoped<IXTestServiceProvider, XTestServiceProvider>();
|
|
services.AddScoped<IXTestRepositoryProvider, XTestRepositoryProvider>();
|
|
#endregion
|
|
|
|
//
|
|
var repositoryType = xDataService.Constants.XRepositoryType.EF;
|
|
|
|
//
|
|
// Register String Service ...
|
|
services.AddXStringService<XApiDbContext>(
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
|
|
//
|
|
// Register Terms and Conditions Service ...
|
|
services.AddXTermsConditionsService(
|
|
lifeTime: lifeTime,
|
|
configuration: configuration
|
|
);
|
|
|
|
//
|
|
// Register Tag Service ...
|
|
services.AddXTagService<XApiDbContext>(
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
|
|
//
|
|
// Register File Service ...
|
|
services.AddXFileService<XApiDbContext>(
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
|
|
//
|
|
// Register Category Service ...
|
|
services.AddXCategoryServiceConfiguration(configuration);
|
|
services.AddXCategoryService<XApiDbContext>(
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
|
|
//
|
|
// Register Webinar Service ...
|
|
services.AddXWebinarService<XApiDbContext>(
|
|
lifeTime: lifeTime,
|
|
repositoryType: repositoryType
|
|
);
|
|
}
|
|
#endregion
|
|
}
|
|
} |