Skip to content

Commit

Permalink
add feature management and remove mail kit provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmoudalaskalany committed Dec 4, 2024
1 parent 4cd5072 commit 8a02aa9
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 129 deletions.
20 changes: 20 additions & 0 deletions Template.Api/Authorization/HangFireAuthorizationFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Hangfire.Dashboard;

namespace Template.Api.Authorization
{
/// <summary>
/// Hang Fire
/// </summary>
public class HangFireAuthorizationFilter : IDashboardAuthorizationFilter
{
/// <summary>
/// Authorize
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public bool Authorize(DashboardContext context)
{
return true;
}
}
}
2 changes: 1 addition & 1 deletion Template.Api/Extensions/ConfigureDependencyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public static IServiceCollection RegisterServices(this IServiceCollection servic
services.RegisterAutoMapper();
services.RegisterCommonServices(configuration);
services.RegisterApiMonitoring();
services.AddControllers();
services.RegisterApiVersioning();
services.RegisterSwaggerConfig();
services.RegisterLowerCaseUrls();
services.AddControllers();
return services;
}

Expand Down
10 changes: 10 additions & 0 deletions Template.Api/Extensions/ConfigureMiddlewareExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using System.Linq;
using Asp.Versioning.ApiExplorer;
using FluentScheduler;
using Hangfire;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Swashbuckle.AspNetCore.SwaggerUI;
using Template.Api.Authorization;
using Template.Application.Services.BackgroundJobs.Jobs;
using Template.Domain;
using Template.Infrastructure.Context;
Expand Down Expand Up @@ -133,7 +135,15 @@ public static void UseFluentScheduler(this IApplicationBuilder app, IConfigurati
{
JobManager.Initialize(new MyRegistry());
}
}

public static void UseHangFire(this IApplicationBuilder app)
{
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{
Authorization = new[] { new HangFireAuthorizationFilter() }

});
}
}
}
5 changes: 4 additions & 1 deletion Template.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"SwaggerAuth": {
"Username": "mahmoud",
"Password": "123456"
"Password": "123456"
},
"Jwt": {
"SecretKey": "veryDifficultSuperSecretKeyApplyDeveloper@@123-RT",
Expand Down Expand Up @@ -69,6 +69,9 @@
"Password": "123456",
"EnableSsl": "false"
},
"FeatureManagement": {
"EnableHangFire": false
},
"Environment": "Dev",
"AllowedHosts": "*"
}
55 changes: 6 additions & 49 deletions Template.Common/Extensions/ConfigureDependencyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Template.Common.Helpers.FileHelpers.StorageHelper;
using Template.Common.Helpers.HttpClient;
using Template.Common.Helpers.HttpClient.RestSharp;
using Template.Common.Helpers.MailKitHelper;
using Template.Common.Helpers.MediaUploader;
using Template.Common.Helpers.TokenGenerator;
using Template.Common.Services;
Expand All @@ -21,13 +20,13 @@ namespace Template.Common.Extensions
[ExcludeFromCodeCoverage]
public static class ConfigureDependencyExtension
{
public static IServiceCollection RegisterCommonServices(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection RegisterCommonServices(this IServiceCollection services,
IConfiguration configuration)
{
services.AddCors();
services.RegisterFileServices();
services.RegisterMainCore();
services.RegisterEmailMetadata(configuration);
//services.AddApiDocumentationServices(configuration);
services.RegisterAuthentication(configuration);
services.RegisterHttpClientHelpers();
return services;
Expand All @@ -41,7 +40,6 @@ private static void RegisterMainCore(this IServiceCollection services)
services.AddTransient<IResponseResult, ResponseResult>();
services.AddTransient<IFinalResult, FinalResult>();
services.AddSingleton<ISendMail, SendMail>();
services.AddSingleton<ISendMailKit, SendMailKit>();
services.AddTransient<ITokenGenerator, TokenGenerator>();
services.AddTransient<IUploaderConfiguration, UploaderConfiguration>();
}
Expand Down Expand Up @@ -91,54 +89,13 @@ private static void RegisterAuthentication(this IServiceCollection services, ICo
ValidAudience = configuration["Jwt:Audience"],
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:SecretKey"] ?? string.Empty)),
IssuerSigningKey =
new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(configuration["Jwt:SecretKey"] ?? string.Empty)),
};
});
}
}


//private static void AddApiDocumentationServices(this IServiceCollection services, IConfiguration configuration)
//{
// services.AddSwaggerGen(options =>
// {
// var title = configuration["SwaggerConfig:Title"];
// var version = configuration["SwaggerConfig:Version"];
// var docPath = configuration["SwaggerConfig:DocPath"];
// options.SwaggerDoc(version, new OpenApiInfo { Title = title, Version = version });
// if (docPath != null)
// {
// var filePath = Path.Combine(AppContext.BaseDirectory, docPath);
// options.IncludeXmlComments(filePath);
// }

// var security = new OpenApiSecurityRequirement
// {
// {
// new OpenApiSecurityScheme
// {
// Reference = new OpenApiReference
// {
// Type = ReferenceType.SecurityScheme,
// Id = "Bearer"
// }
// },
// new string[] { }

// }
// };
// options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
// {
// Name = "Authorization",
// Type = SecuritySchemeType.ApiKey,
// Scheme = "Bearer",
// BearerFormat = "JWT",
// In = ParameterLocation.Header,
// Description = "JWT Authorization header using the Bearer scheme."
// });
// options.AddSecurityRequirement(security);
// options.OperationFilter<LanguageHeader>();
// });
// services.AddSwaggerGenNewtonsoftSupport();
//}
}
}
7 changes: 7 additions & 0 deletions Template.Common/FeatureFlags/FeatureFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Template.Common.FeatureFlags
{
public enum FeatureFlags
{
EnableHangFire = 1
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Template.Common.Helpers.MailKitHelper
namespace Template.Common.Helpers.EmailHelper
{
[ExcludeFromCodeCoverage]
public class EmailMetadata
Expand Down
14 changes: 0 additions & 14 deletions Template.Common/Helpers/MailKitHelper/EmailMessage.cs

This file was deleted.

7 changes: 0 additions & 7 deletions Template.Common/Helpers/MailKitHelper/ISendMailKit.cs

This file was deleted.

55 changes: 0 additions & 55 deletions Template.Common/Helpers/MailKitHelper/SendMailKit.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Template.Common/Template.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="4.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.0" />
<PackageReference Include="NETCore.MailKit" Version="2.1.0" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="8.0.0" />
Expand Down

0 comments on commit 8a02aa9

Please sign in to comment.