Created
September 10, 2022 11:23
-
-
Save Rajdeep-Das/e1ffe4169f5db44c81cd6f34f43ef1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.DependencyInjection; | |
using Redis.OM; | |
using System.Runtime.InteropServices; | |
using WatchLogger.Exceptions; | |
using WatchLogger.Helpers; | |
using WatchLogger.HostedService; | |
namespace WatchLogger | |
{ | |
// Extension method and Class used to add the middleware to the HTTP request pipeline. | |
public static class WatchLoggerExtensions | |
{ | |
public static IApplicationBuilder UseWatchLogger(this IApplicationBuilder builder) | |
{ | |
builder.UseMvc(); | |
return builder.UseMiddleware<WatchLogger>(); | |
} | |
public static IApplicationBuilder UseWatchLoggerExceptionLogger(this IApplicationBuilder builder) | |
{ | |
return builder.UseMiddleware<WatchLoggerExceptionLogger>(); | |
} | |
public static IServiceCollection AddWatchLoggerServices(this IServiceCollection services, [Optional] Action<WatchLogConfig> configureOptions) | |
{ | |
var options = new WatchLogConfig(); | |
if (configureOptions != null) | |
configureOptions(options); | |
WatchLogExternalDbConfig.ConnectionString = options.SetExternalDbConnString; | |
if (string.IsNullOrEmpty(WatchLogExternalDbConfig.ConnectionString)) | |
throw new WatchLogDBException("Missing connection string."); | |
/* ----- Add Controller & UI Service --- */ | |
// services.AddMvc().AddApplicationPart(typeof(WatchLoggerExtensions).Assembly); | |
services.AddMvcCore(x => | |
{ | |
x.EnableEndpointRouting = false; | |
}).AddApplicationPart(typeof(WatchLoggerExtensions).Assembly); | |
services.AddSingleton(new RedisConnectionProvider(WatchLogExternalDbConfig.ConnectionString)); | |
// Create Redis Index | |
services.AddHostedService<IndexCreationService>(); | |
services.AddSingleton(new RedisStackHelper()); | |
return services; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment