From ee4065ad5f3115a4ed5906ad71737c5fe15ef633 Mon Sep 17 00:00:00 2001 From: Dona Jose Date: Wed, 24 Sep 2025 20:49:51 +0530 Subject: [PATCH 1/2] s# initial changes --- BaseControllers/EbFileBaseController.cs | 70 +++- External/StaticFileController.cs | 436 ++++++++++++++++-------- Startup.cs | 33 +- 3 files changed, 384 insertions(+), 155 deletions(-) diff --git a/BaseControllers/EbFileBaseController.cs b/BaseControllers/EbFileBaseController.cs index 9f49f26..0a72cf8 100644 --- a/BaseControllers/EbFileBaseController.cs +++ b/BaseControllers/EbFileBaseController.cs @@ -1,8 +1,13 @@ using ExpressBase.Common; +using ExpressBase.Common.Constants; +using ExpressBase.Common.LocationNSolution; using ExpressBase.Common.ServiceClients; +using ExpressBase.Objects.ServiceStack_Artifacts; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Hosting; +using ServiceStack.Redis; using System; namespace ExpressBase.Web.BaseControllers @@ -11,15 +16,35 @@ public class EbFileBaseController : Controller { protected EbStaticFileClient FileClient { get; set; } - public EbFileBaseController(IEbStaticFileClient _sfc) + protected EbStaticFileClient2 FileClient2 { get; set; } + + protected RedisClient Redis { get; set; } + + protected PooledRedisClientManager PooledRedisManager { get; set; } + + public string Host { get; set; } + + public string ExtSolutionId { get; set; } + + public string IntSolutionId { get; set; } + + public EbFileBaseController(IEbStaticFileClient _sfc, EbStaticFileClient2 _sfc2, IRedisClient _redis, PooledRedisClientManager pooledRedisManager) { this.FileClient = _sfc as EbStaticFileClient; + this.FileClient2 = _sfc2; + this.Redis = _redis as RedisClient; + this.PooledRedisManager = pooledRedisManager; } public override void OnActionExecuting(ActionExecutingContext context) { base.OnActionExecuting(context); + Host = context.HttpContext.Request.Host.Host.Replace(RoutingConstants.WWWDOT, string.Empty).Replace(RoutingConstants.LIVEHOSTADDRESS, string.Empty).Replace(RoutingConstants.STAGEHOSTADDRESS, string.Empty).Replace(RoutingConstants.LOCALHOSTADDRESS, string.Empty); + + ExtSolutionId = Host.Replace(RoutingConstants.DASHDEV, string.Empty); + IntSolutionId = this.GetIsolutionId(ExtSolutionId); + string sBToken = context.HttpContext.Request.Cookies[RoutingConstants.BEARER_TOKEN]; string sRToken = context.HttpContext.Request.Cookies[RoutingConstants.REFRESH_TOKEN]; @@ -40,5 +65,48 @@ public override void OnActionExecuted(ActionExecutedContext context) base.OnActionExecuted(context); } + + public string GetIsolutionId(string esid) + { + string solnId = string.Empty; + + if (esid == CoreConstants.MYACCOUNT) + solnId = CoreConstants.EXPRESSBASE; + else if (esid == CoreConstants.ADMIN) + solnId = CoreConstants.ADMIN; + else if (this.Redis != null) + { + if (this.PooledRedisManager != null) + { + using (var redis = this.PooledRedisManager.GetReadOnlyClient()) + { + solnId = redis.Get(string.Format(CoreConstants.SOLUTION_ID_MAP, esid)); + } + } + else + solnId = this.Redis.Get(string.Format(CoreConstants.SOLUTION_ID_MAP, esid)); + } + return solnId; + } + + public Eb_Solution GetSolutionObject(string cid) + { + Eb_Solution s_obj = null; + try + { + if (this.PooledRedisManager != null) + { + using (var redis = this.PooledRedisManager.GetReadOnlyClient()) + s_obj = redis.Get(string.Format("solution_{0}", cid)); + } + else + s_obj = this.Redis.Get(String.Format("solution_{0}", cid)); + } + catch (Exception e) + { + Console.WriteLine(e.Message + e.StackTrace); + } + return s_obj; + } } } \ No newline at end of file diff --git a/External/StaticFileController.cs b/External/StaticFileController.cs index 76ab0a7..c06a42a 100644 --- a/External/StaticFileController.cs +++ b/External/StaticFileController.cs @@ -2,47 +2,69 @@ using ExpressBase.Common.Constants; using ExpressBase.Common.EbServiceStack.ReqNRes; using ExpressBase.Common.Enums; +using ExpressBase.Common.LocationNSolution; using ExpressBase.Common.ServiceClients; +using ExpressBase.Common.WebApi.RequestNResponse; using ExpressBase.Web.BaseControllers; using Microsoft.AspNetCore.Mvc; using Microsoft.Net.Http.Headers; using ServiceStack; +using ServiceStack.Redis; using System; +using System.IO; using System.Linq; namespace ExpressBase.FileWeb.Controllers { public class StaticFileExtController : EbFileBaseController { - public StaticFileExtController(IEbStaticFileClient _sfc) : base(_sfc) { } + public StaticFileExtController(IEbStaticFileClient _sfc, EbStaticFileClient2 _sfc2, IRedisClient _redis, PooledRedisClientManager pooledRedisManager) : base(_sfc, _sfc2, _redis, pooledRedisManager) { } + + public bool IsNewFileServer => !string.IsNullOrEmpty(IntSolutionId) && (GetSolutionObject(IntSolutionId)?.SolutionSettings?.EnableNewFileServer ?? false); [HttpGet("images/logo/{solnid}")] public IActionResult GetLogo(string solnid) { solnid = solnid.SplitOnLast(CharConstants.DOT).First() + StaticFileConstants.DOTPNG; - DownloadFileResponse dfs = null; ActionResult resp = new EmptyResult(); - try + if (IsNewFileServer) { - - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; - - dfs = this.FileClient.Get - (new DownloadLogoExtRequest - { - SolnId = solnid.Split(CharConstants.DOT)[0], - }); - if (dfs.StreamWrapper != null) + DownloadFileResponse2 dfs = this.FileClient2.DownloadLogo(solnid); + if (dfs?.FileBytes != null) { - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(solnid)); + MemoryStream ms = new MemoryStream(dfs.FileBytes); + ms.Position = 0; + resp = new FileStreamResult(ms, StaticFileConstants.GetMimeType(solnid)); + } + else if (dfs?.PreSignedUrl != null) + { + resp = Redirect(dfs.PreSignedUrl); } } - catch (Exception e) + else { - Console.WriteLine("Exception: " + e.Message.ToString()); + DownloadFileResponse dfs = null; + try + { + dfs = this.FileClient.Get + (new DownloadLogoExtRequest + { + SolnId = solnid.Split(CharConstants.DOT)[0], + }); + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(solnid)); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); + } } + + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; return resp; } @@ -117,208 +139,322 @@ private string GetMime(string fname) public class StaticFileController : EbFileBaseController { - public StaticFileController( IEbStaticFileClient _sfc) : base(_sfc) { } + public StaticFileController(IEbStaticFileClient _sfc, EbStaticFileClient2 _sfc2, IRedisClient _redis, PooledRedisClientManager pooledRedisManager) : base(_sfc, _sfc2, _redis, pooledRedisManager) { } - private const string UnderScore = "_"; - - private const string RejexPattern = " *[\\~#%&*{}/:<>?|\"-]+ *"; + public bool IsNewFileServer => !string.IsNullOrEmpty(IntSolutionId) && (GetSolutionObject(IntSolutionId)?.SolutionSettings?.EnableNewFileServer ?? false); [HttpGet("images/dp/{userid}")] public IActionResult GetDP(string userid) { string uid = userid.Split(CharConstants.DOT).First(); + string filetype = userid.Split(CharConstants.DOT).Last(); string fname = userid.SplitOnLast(CharConstants.DOT).First() + StaticFileConstants.DOTPNG; - - DownloadFileResponse dfs = null; ActionResult resp = new EmptyResult(); - try + ImageMeta ImageMeta = new ImageMeta { - dfs = this.FileClient.Get - (new DownloadDpRequest - { - ImageInfo = new ImageMeta - { - FileName = uid, - FileType = StaticFileConstants.PNG, - FileCategory = EbFileCategory.Dp - } - }); + FileName = uid, + FileType = filetype, + FileCategory = EbFileCategory.Dp, + }; - if (dfs.StreamWrapper != null) + if (IsNewFileServer) + { + try { - dfs.StreamWrapper.Memorystream.Position = 0; - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(fname)); + DownloadFileResponse2 dfs = this.FileClient2.DownloadFile(ImageMeta, "/download/image", this.IntSolutionId, Convert.ToInt32(uid)); + + if (dfs?.FileBytes != null) + { + MemoryStream ms = new MemoryStream(dfs.FileBytes); + ms.Position = 0; + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; + resp = new FileStreamResult(ms, GetMime(fname)); + } + else if (dfs?.PreSignedUrl != null) + { + resp = Redirect(dfs.PreSignedUrl); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); + resp = new EmptyResult(); } } - catch (Exception e) + else { - Console.WriteLine("Exception: " + e.Message.ToString()); - resp = new EmptyResult(); - } - return resp; - } - - [HttpGet("files/loc/{filename}")] - public IActionResult GetLocFiles(string filename) - { - filename = filename.SplitOnLast(CharConstants.DOT).First() + StaticFileConstants.DOTPNG; - - DownloadFileResponse dfs = null; - ActionResult resp = new EmptyResult(); + DownloadFileResponse dfs = null; - try - { - if (filename.StartsWith(StaticFileConstants.LOC)) + try { - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; - - dfs = this.FileClient.Get - (new DownloadFileRequest - { - FileDetails = new FileMeta - { - FileName = filename, - FileType = StaticFileConstants.PNG, - FileCategory = EbFileCategory.LocationFile - } - }); + dfs = this.FileClient.Get(new DownloadDpRequest { ImageInfo = ImageMeta }); + + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; + resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(fname)); + } } - - if (dfs.StreamWrapper != null) + catch (Exception e) { - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + Console.WriteLine("Exception: " + e.Message.ToString()); + resp = new EmptyResult(); } } - catch (Exception e) - { - Console.WriteLine("Exception: " + e.Message.ToString()); - resp = new EmptyResult(); - } return resp; } + //[HttpGet("files/loc/{filename}")] + //public IActionResult GetLocFiles(string filename) + //{ + // filename = filename.SplitOnLast(CharConstants.DOT).First() + StaticFileConstants.DOTPNG; + + // DownloadFileResponse dfs = null; + // ActionResult resp = new EmptyResult(); + + // try + // { + // if (filename.StartsWith(StaticFileConstants.LOC)) + // { + // HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; + + // dfs = this.FileClient.Get + // (new DownloadFileRequest + // { + // FileDetails = new FileMeta + // { + // FileName = filename, + // FileType = StaticFileConstants.PNG, + // FileCategory = EbFileCategory.LocationFile + // } + // }); + // } + + // if (dfs.StreamWrapper != null) + // { + // dfs.StreamWrapper.Memorystream.Position = 0; + // resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + // } + // } + // catch (Exception e) + // { + // Console.WriteLine("Exception: " + e.Message.ToString()); + // resp = new EmptyResult(); + // } + // return resp; + //} + [HttpGet("files/{filename}")] public IActionResult GetFile(string filename) { - DownloadFileResponse dfs = null; - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; ActionResult resp = new EmptyResult(); - - try + if (IsNewFileServer) { - dfs = this.FileClient.Get - (new DownloadFileByIdRequest - { - FileDetails = new FileMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.File } - }); - if (dfs.StreamWrapper != null) + try { - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + FileMeta fileMeta = new FileMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.File, FileName = filename }; + DownloadFileResponse2 dfs = this.FileClient2.DownloadFile(fileMeta, "/download/file", this.IntSolutionId); + if (dfs?.FileBytes != null) + { + MemoryStream ms = new MemoryStream(dfs.FileBytes); + ms.Position = 0; + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=2628000"; + resp = new FileStreamResult(ms, GetMime(filename)); + } + else if (dfs?.PreSignedUrl != null) + { + resp = Redirect(dfs.PreSignedUrl); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); + resp = new EmptyResult(); } } - catch (Exception e) + else { - Console.WriteLine("Exception: " + e.Message.ToString()); - } - return resp; - } + DownloadFileResponse dfs = null; - [HttpGet("files/ref/{filename}")] - public IActionResult GetFileByRefId(string filename) - { - DownloadFileResponse dfs = null; - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; - ActionResult resp = new EmptyResult(); - try - { - dfs = this.FileClient.Get - (new DownloadFileByRefIdRequest - { - FileDetails = new FileMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.File } - }); - if (dfs.StreamWrapper != null) + try { - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + dfs = this.FileClient.Get + (new DownloadFileByIdRequest + { + FileDetails = new FileMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.File } + }); + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); } } - catch (Exception e) - { - Console.WriteLine("Exception: " + e.StackTrace.ToString() + e.Message.ToString()); - } + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; + return resp; } + //[HttpGet("files/ref/{filename}")] + //public IActionResult GetFileByRefId(string filename) + //{ + // DownloadFileResponse dfs = null; + // HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; + // ActionResult resp = new EmptyResult(); + // try + // { + // dfs = this.FileClient.Get + // (new DownloadFileByRefIdRequest + // { + // FileDetails = new FileMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.File } + // }); + // if (dfs.StreamWrapper != null) + // { + // dfs.StreamWrapper.Memorystream.Position = 0; + // resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + // } + // } + // catch (Exception e) + // { + // Console.WriteLine("Exception: " + e.StackTrace.ToString() + e.Message.ToString()); + // } + // return resp; + //} + [HttpGet("images/{filename}")] public IActionResult GetImageById(string filename, string qlty) { - DownloadFileResponse dfs = null; - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; ActionResult resp = new EmptyResult(); + if (IsNewFileServer) + { + try + { + ImageMeta ImageMeta = new ImageMeta + { + FileName = filename, + FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), + FileCategory = EbFileCategory.Images, + ImageQuality = ImageQuality.original + }; + + DownloadFileResponse2 dfs = this.FileClient2.DownloadFile(ImageMeta, "/download/image", this.IntSolutionId); + + if (dfs?.FileBytes != null) + { + MemoryStream ms = new MemoryStream(dfs.FileBytes); + ms.Position = 0; + resp = new FileStreamResult(ms, StaticFileConstants.GetMimeType(filename)); + } + else if (dfs?.PreSignedUrl != null) + { + resp = Redirect(dfs.PreSignedUrl); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); + } + } + else + { + try + { + DownloadImageByIdRequest dfq = new DownloadImageByIdRequest(); + DownloadFileResponse dfs = null; + dfq.ImageInfo = new ImageMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.Images, ImageQuality = ImageQuality.original }; - DownloadImageByIdRequest dfq = new DownloadImageByIdRequest(); + Console.WriteLine("Image Info: " + dfq.ImageInfo.ToString()); - try - { - dfq.ImageInfo = new ImageMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.Images, ImageQuality = ImageQuality.original }; + dfs = this.FileClient.Get(dfq); - Console.WriteLine("Image Info: " + dfq.ImageInfo.ToString()); + if (dfs.StreamWrapper != null) + { + Console.WriteLine("Image Size: " + dfs.StreamWrapper.Memorystream.Length); - dfs = this.FileClient.Get(dfq); + dfs.StreamWrapper.Memorystream.Position = 0; + resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + } - if (dfs.StreamWrapper != null) + } + catch (Exception e) { - Console.WriteLine("Image Size: " + dfs.StreamWrapper.Memorystream.Length); - - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + Console.WriteLine("Exception: " + e.Message.ToString()); } - - } - catch (Exception e) - { - Console.WriteLine("Exception: " + e.StackTrace.ToString() + e.Message.ToString()); } + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; + return resp; } [HttpGet("images/{qlty}/{filename}")] public IActionResult GetImageQualById(string filename, string qlty) { - DownloadFileResponse dfs = null; - HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; ActionResult resp = new EmptyResult(); + if (IsNewFileServer) + { + try + { + ImageMeta ImageMeta = new ImageMeta + { + FileName = filename, + FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), + FileCategory = EbFileCategory.Images, + ImageQuality = Enum.Parse(qlty) + }; + + DownloadFileResponse2 dfs = this.FileClient2.DownloadFile(ImageMeta, "/download/image", this.IntSolutionId, 0, null, ImageMeta.ImageQuality); + + if (dfs?.FileBytes != null) + { + MemoryStream ms = new MemoryStream(dfs.FileBytes); + ms.Position = 0; + resp = new FileStreamResult(ms, StaticFileConstants.GetMimeType(filename)); + } + else if (dfs?.PreSignedUrl != null) + { + resp = Redirect(dfs.PreSignedUrl); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message.ToString()); + } + } + else + { + DownloadFileResponse dfs = null; - DownloadImageByIdRequest dfq = new DownloadImageByIdRequest(); + DownloadImageByIdRequest dfq = new DownloadImageByIdRequest(); - try - { - dfq.ImageInfo = new ImageMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.Images, ImageQuality = Enum.Parse(qlty) }; - - Console.WriteLine("Image Info: " + dfq.ImageInfo.ToJson()); + try + { + dfq.ImageInfo = new ImageMeta { FileRefId = Convert.ToInt32(filename.SplitOnLast(CharConstants.DOT).First()), FileCategory = EbFileCategory.Images, ImageQuality = Enum.Parse(qlty) }; - this.FileClient.Timeout = new TimeSpan(0, 5, 0); + this.FileClient.Timeout = new TimeSpan(0, 5, 0); - dfs = this.FileClient.Get(dfq); + dfs = this.FileClient.Get(dfq); - if (dfs.StreamWrapper != null) + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + } + } + catch (Exception e) { - Console.WriteLine("Image Size: " + dfs.StreamWrapper.Memorystream.Length); - - dfs.StreamWrapper.Memorystream.Position = 0; - resp = new FileStreamResult(dfs.StreamWrapper.Memorystream, GetMime(filename)); + Console.WriteLine("Exception: " + e.Message.ToString()); } } - catch (Exception e) - { - Console.WriteLine("Exception: " + e.StackTrace.ToString() + e.Message.ToString()); - } - return resp; + HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000"; + + return resp; } //[HttpPost] diff --git a/Startup.cs b/Startup.cs index b68a786..3abf2e3 100644 --- a/Startup.cs +++ b/Startup.cs @@ -1,12 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using ExpressBase.Common; using ExpressBase.Common.ServiceClients; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using ServiceStack.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace ExpressBase.FileWeb { @@ -22,6 +24,29 @@ public void ConfigureServices(IServiceCollection services) { return new EbStaticFileClient(); }); + + services.AddHttpClient(); + + // var redisServer = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_SERVER); + var redisPassword = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_PASSWORD); + var redisPort = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_PORT); + //var redisConnectionString = string.Format("redis://{0}@{1}:{2}", redisPassword, redisServer, redisPort); + + var redisServer = "127.0.0.1"; + string redisConnectionString = string.Format("redis://{0}:{1}", redisServer, redisPort); + + var redisManager = new RedisManagerPool(redisConnectionString); + services.AddScoped(serviceProvider => + { + return redisManager.GetClient(); + }); + + var listRWRedis = new List() { redisConnectionString }; var listRORedis = new List() { redisConnectionString.Replace("-master", "-replicas") }; + PooledRedisClientManager pooledRedisManager = new PooledRedisClientManager(listRWRedis, listRORedis); + services.AddSingleton(serviceProvider => + { + return pooledRedisManager; + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 051b87ca85d1b5ec560f71fa52e1b094ab9689bf Mon Sep 17 00:00:00 2001 From: Dona Jose Date: Wed, 24 Sep 2025 20:50:52 +0530 Subject: [PATCH 2/2] minor --- Startup.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Startup.cs b/Startup.cs index 3abf2e3..1899f5b 100644 --- a/Startup.cs +++ b/Startup.cs @@ -27,13 +27,13 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpClient(); - // var redisServer = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_SERVER); + var redisServer = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_SERVER); var redisPassword = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_PASSWORD); var redisPort = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_REDIS_PORT); - //var redisConnectionString = string.Format("redis://{0}@{1}:{2}", redisPassword, redisServer, redisPort); + var redisConnectionString = string.Format("redis://{0}@{1}:{2}", redisPassword, redisServer, redisPort); - var redisServer = "127.0.0.1"; - string redisConnectionString = string.Format("redis://{0}:{1}", redisServer, redisPort); + //var redisServer = "127.0.0.1"; + //string redisConnectionString = string.Format("redis://{0}:{1}", redisServer, redisPort); var redisManager = new RedisManagerPool(redisConnectionString); services.AddScoped(serviceProvider =>