Added abstractions
Internal service bus support enabled Added quartz support Reconfigured extensions
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using LiteCharms.Models.Configuraton.Email;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class Email
|
||||
{
|
||||
public static IServiceCollection AddEmailServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.Configure<SmtpSettings>(configuration.GetSection("Email"));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using LiteCharms.Infrastructure.HealthChecks;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class HealthChecks
|
||||
{
|
||||
public static IServiceCollection AddQuartzHealtchCheck(this IServiceCollection services)
|
||||
{
|
||||
services.AddHealthChecks().AddCheck<QuartzHealthCheck>("Quartz");
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddPostgresHealtchCheck(this IServiceCollection services)
|
||||
{
|
||||
services.AddHealthChecks().AddCheck<PostgresHealthCheck>("PostgreSQL");
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddHealthChecksSupport(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddHealthChecks()
|
||||
.AddCheck("Self", () => HealthCheckResult.Healthy());
|
||||
|
||||
//services.AddHealthChecksUI(setup =>
|
||||
//{
|
||||
// setup.AddHealthCheckEndpoint("Lead Generator", $"{configuration["ASPNETCORE_URLS"]}/health");
|
||||
// setup.SetEvaluationTimeInSeconds(15);
|
||||
//}).AddInMemoryStorage(databaseName: "healthuidb");
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,19 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\LiteCharms.snk</AssemblyOriginatorKeyFile>
|
||||
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Warnings And Exclusions -->
|
||||
<PropertyGroup>
|
||||
<NoWarn>$(NoWarn);MA0004</NoWarn>
|
||||
<!-- https://github.com/dotnet/aspnetcore/issues/50836 -->
|
||||
<NoWarn>$(NoWarn);AD0001</NoWarn>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<NoWarn>$(NoWarn);IL2080;IL2065;IL2075;IL2087;IL2057;IL2060;IL2070;IL2067;IL2072;IL2026;IL2104</NoWarn>
|
||||
<NoWarn>$(NoWarn);IL2110;IL2111</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Nuget Package Details -->
|
||||
<PropertyGroup>
|
||||
<PackageId>LiteCharms.Extensions</PackageId>
|
||||
@@ -28,14 +39,6 @@
|
||||
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.AspNetCore.Builder" />
|
||||
<Using Include="Microsoft.Extensions.Configuration" />
|
||||
<Using Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<Using Include="Microsoft.Extensions.Logging" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Health Checks -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
||||
@@ -44,7 +47,8 @@
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Data" Version="9.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
|
||||
<PackageReference Include="Quartz.AspNetCore" Version="3.18.1" />
|
||||
|
||||
<!-- Global Usings -->
|
||||
<Using Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
|
||||
@@ -58,6 +62,7 @@
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.15.3" />
|
||||
|
||||
<!-- Global Usings -->
|
||||
<Using Include="OpenTelemetry.Resources" />
|
||||
@@ -88,6 +93,16 @@
|
||||
<Using Include="Microsoft.EntityFrameworkCore.Metadata.Builders" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="Quartz" />
|
||||
<Using Include="Microsoft.AspNetCore.Builder" />
|
||||
<Using Include="Microsoft.Extensions.Configuration" />
|
||||
<Using Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<Using Include="Microsoft.Extensions.Logging" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Project References -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LiteCharms.Entities\LiteCharms.Entities.csproj" />
|
||||
<ProjectReference Include="..\LiteCharms.Infrastructure\LiteCharms.Infrastructure.csproj" />
|
||||
|
||||
@@ -1,41 +1,7 @@
|
||||
using LiteCharms.Infrastructure.Database;
|
||||
using LiteCharms.Infrastructure.HealthChecks;
|
||||
using LiteCharms.Models.Configuraton.Email;
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class Services
|
||||
public static class Monitoring
|
||||
{
|
||||
public static IServiceCollection AddEmailServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.Configure<SmtpSettings>(configuration.GetSection("Email"));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddHealthChecksSupport(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddHealthChecks()
|
||||
.AddCheck("Self", () => HealthCheckResult.Healthy())
|
||||
.AddCheck<PostgresHealthCheck>("PostgreSQL");
|
||||
|
||||
//services.AddHealthChecksUI(setup =>
|
||||
//{
|
||||
// setup.AddHealthCheckEndpoint("Lead Generator", $"{configuration["ASPNETCORE_URLS"]}/health");
|
||||
// setup.SetEvaluationTimeInSeconds(15);
|
||||
//}).AddInMemoryStorage(databaseName: "healthuidb");
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddLeadGeneratorDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddPooledDbContextFactory<LeadGeneratorDbContext>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString("PostgresLeadGenerator")));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static WebApplicationBuilder AddMonitoring(this WebApplicationBuilder builder)
|
||||
{
|
||||
var serviceName = builder.Configuration.GetValue<string>("Monitoring:ServiceName") ?? "LiteCharms";
|
||||
@@ -0,0 +1,14 @@
|
||||
using LiteCharms.Infrastructure.Database;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class Postgres
|
||||
{
|
||||
public static IServiceCollection AddLeadGeneratorDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddPooledDbContextFactory<LeadGeneratorDbContext>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString("PostgresLeadGenerator")));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using LiteCharms.Abstractions;
|
||||
using LiteCharms.Infrastructure.Quartz;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class Quartz
|
||||
{
|
||||
private const string databaseConfigName = "PostgresScheduler";
|
||||
|
||||
public static IServiceCollection AddQuartzScheduler(this IServiceCollection services, string schedulerName, string schedulerId, IConfiguration configuration)
|
||||
{
|
||||
var connectionString = configuration.GetConnectionString(databaseConfigName);
|
||||
|
||||
services.ConfigureCommon();
|
||||
|
||||
services.AddQuartz(config =>
|
||||
{
|
||||
config.SchedulerName = schedulerName;
|
||||
config.SchedulerId = schedulerId;
|
||||
config.InterruptJobsOnShutdown = true;
|
||||
config.InterruptJobsOnShutdownWithWait = true;
|
||||
config.MaxBatchSize = 5;
|
||||
|
||||
config.UseSimpleTypeLoader();
|
||||
config.UseDefaultThreadPool(options => options.MaxConcurrency = 1);
|
||||
config.UseTimeZoneConverter();
|
||||
|
||||
config.UsePersistentStore(storage =>
|
||||
{
|
||||
storage.PerformSchemaValidation = false;
|
||||
|
||||
storage.UseSystemTextJsonSerializer();
|
||||
storage.SetProperty("quartz.jobStore.clustered", "true");
|
||||
storage.SetProperty("quartz.jobStore.tablePrefix", "quartz_");
|
||||
|
||||
storage.UsePostgres(connectionString!);
|
||||
storage.UseClustering(cluster =>
|
||||
{
|
||||
cluster.CheckinInterval = TimeSpan.FromSeconds(30);
|
||||
cluster.CheckinMisfireThreshold = TimeSpan.FromSeconds(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection ConfigureCommon(this IServiceCollection services)
|
||||
{
|
||||
services.Configure<QuartzOptions>(options =>
|
||||
{
|
||||
options.Scheduling.IgnoreDuplicates = true;
|
||||
options.Scheduling.OverWriteExistingData = true;
|
||||
options["quartz.plugin.jobHistory.type"] = "Quartz.Plugin.History.LoggingJobHistoryPlugin, Quartz.Plugins";
|
||||
options["quartz.plugin.triggerHistory.type"] = "Quartz.Plugin.History.LoggingTriggerHistoryPlugin, Quartz.Plugins";
|
||||
});
|
||||
|
||||
services.AddTransient<RetryJobListener>();
|
||||
services.AddTransient<IJobOrchestrator, JobOrchestrator>();
|
||||
services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using LiteCharms.Abstractions;
|
||||
using LiteCharms.Infrastructure.ServiceBus;
|
||||
using LiteCharms.Infrastructure.ServiceBus.Exchanges;
|
||||
|
||||
namespace LiteCharms.Extensions;
|
||||
|
||||
public static class ServiceBus
|
||||
{
|
||||
public static IServiceCollection AddGeneralServiceBus(this IServiceCollection services) => services
|
||||
.AddSingleton<GeneralServiceBus>()
|
||||
.AddHostedService<GeneralExchange>()
|
||||
.AddKeyedTransient<IEventBus, GeneralServiceBus>(Constants.GeneralServiceBus)
|
||||
.AddMemoryCache();
|
||||
|
||||
public static IServiceCollection AddEmailServiceBus(this IServiceCollection services) => services
|
||||
.AddSingleton<EmailServiceBus>()
|
||||
.AddHostedService<EmailExchange>()
|
||||
.AddKeyedTransient<IEventBus, EmailServiceBus>(Constants.EmailServiceBus)
|
||||
.AddMemoryCache();
|
||||
|
||||
public static IServiceCollection AddSalesServiceBus(this IServiceCollection services) => services
|
||||
.AddSingleton<SalesServiceBus>()
|
||||
.AddHostedService<SalesExchange>()
|
||||
.AddKeyedTransient<IEventBus, SalesServiceBus>(Constants.SalesServiceBus)
|
||||
.AddMemoryCache();
|
||||
}
|
||||
Reference in New Issue
Block a user