Cracker
Cracker
CC#
Created by Cracker on 8/12/2024 in #help
How do I manage singleton Regex initialization in Scoped service ?
both IMaskingOperator and IMaskingPolicy is scoped service. I have regex pattern used with value of scoped service. In this case for performance, how can I ensure the regex is initialized only once ?
public class DefaultMaskingOperator : IMaskingOperator
{
private Regex regex;
public DefaultMaskingOperator(IMaskingPolicy policy)
{
string pattern = $"...{policy.MaskKeyList}...";
regex = new Regex(pattern,RegexOptions.Compiled);
}

public string MaskWithRegex(string input)
{
string output = string.Empty;
var matches = regex.Matches(input);
//...
return output;
}
}
public class DefaultMaskingOperator : IMaskingOperator
{
private Regex regex;
public DefaultMaskingOperator(IMaskingPolicy policy)
{
string pattern = $"...{policy.MaskKeyList}...";
regex = new Regex(pattern,RegexOptions.Compiled);
}

public string MaskWithRegex(string input)
{
string output = string.Empty;
var matches = regex.Matches(input);
//...
return output;
}
}
16 replies
CC#
Created by Cracker on 8/8/2024 in #help
YARP vs Basic HTTP Redirect
No description
12 replies
CC#
Created by Cracker on 3/1/2024 in #help
HttpClientFactory and Keep-Alive
No description
3 replies
CC#
Created by Cracker on 10/26/2023 in #help
❔ Evaluating C# Expressions At Runtime
I am looking alternative ways to evaluate C# expression at runtime. I have used Roslyn Scripting API CSharpScript.RunAsync but as mentioned github issues, its not designed to be called continuously because it keep creating new assembly in memory and not unloaded, causes memory leak (https://github.com/dotnet/roslyn/issues/41722)
6 replies
CC#
Created by Cracker on 10/25/2023 in #help
❔ Memory Leak Dump Analysis Local Load Test
No description
40 replies
CC#
Created by Cracker on 6/14/2023 in #help
❔ ✅ How to implement pool tracking in concurrent list ?
I am trying to add tracking to my logging service. (Web API project) Once track count is matched, I disbound the ConcurrentBag and send list to logger service. I need review in this approach where I don't want to lose log data since this method is called in every request.
private readonly ConcurrentBag<object> _objects = new ConcurrentBag<object>();

public void Log<T>(T data) where T : class
{
try
{
_objects.Add(data);
if (_objects.Count >= _logOption.TrackCount)
{
Task.Factory.StartNew(async () =>
{
var dataList = new List<object>();
for (int i = 0; i < _logOption.TrackCount; i++)
{
if (_objects.TryTake(out object item))

{
dataList.Add(item);
}
}
await SendToKafkaApi(dataList);
});
}
}
catch (Exception ex)
{
LogOnFile(ex);
}
}
private readonly ConcurrentBag<object> _objects = new ConcurrentBag<object>();

public void Log<T>(T data) where T : class
{
try
{
_objects.Add(data);
if (_objects.Count >= _logOption.TrackCount)
{
Task.Factory.StartNew(async () =>
{
var dataList = new List<object>();
for (int i = 0; i < _logOption.TrackCount; i++)
{
if (_objects.TryTake(out object item))

{
dataList.Add(item);
}
}
await SendToKafkaApi(dataList);
});
}
}
catch (Exception ex)
{
LogOnFile(ex);
}
}
52 replies
CC#
Created by Cracker on 2/26/2023 in #help
✅ Recursive Data Model Required Error in ASP.NET
4 replies
CC#
Created by Cracker on 2/17/2023 in #help
❔ How to handle DNS-IP Changes while use of static HttpClient in v4.8 ?
There is SocketsHttpHandler overload available in netcore2.1 but how do I handle dns-ip changes in framework 4.8 project ?
5 replies
CC#
Created by Cracker on 2/16/2023 in #help
❔ Directory.Packages.props Support Floating Versions
Hey, is it possible to support floating version rules in Directory.Packages.props ?
3 replies
CC#
Created by Cracker on 2/14/2023 in #help
✅ ILGenerator Object Mapper Property Set
Hey, I have following object mapper for non nested class types https://www.paste.org/124478. There are some use cases where return value of Convert method is not re-assigned to destination type, therefore the passed TTgt target argument is not updated since the reference properties are not set directly, therefore I added "ref" wrapper but I don't want to change existing codes to "ref" version. How can I update the existing ILGenerator that maps the properties explicitly, meaning it will update the argument target parameter as reference
3 replies
CC#
Created by Cracker on 1/13/2023 in #help
❔ Kafka Producer Timeouts And How To Detect Undelivered Messages
4 replies
CC#
Created by Cracker on 12/14/2022 in #help
❔ Async Await On Logging - Waiting Response Without Await Keyword
I have logging service where I call the logger.log async method without awaiting the response, expected behaviour is that the method calls logger.log will return the response without await the log response, but its otherwise
21 replies
CC#
Created by Cracker on 11/30/2022 in #help
❔ Ctor DI vs IServiceProvider.GetService
How often and when do you use IServiceProvider.GetService() for retrieving dependency over injecting dependency through constructor ?
6 replies
CC#
Created by Cracker on 11/9/2022 in #help
❔ DateTime.Now UtcNow and UnixTimestamp
24 replies
CC#
Created by Cracker on 10/26/2022 in #help
SourceGenerator is not working with .net48 as nuget package reference
3 replies
CC#
Created by Cracker on 10/14/2022 in #help
Source Generator InterfaceDecleration-IdentifierToken Syntax Tree Issue
3 replies
CC#
Created by Cracker on 10/12/2022 in #help
Source Generator For NuGet References
Hey, I have source generator project which reads metadata of dll references and via that information creates additional interfaces. Now I changed target project to read those DLLs as NuGet references. Is it possible to read NuGet dll metadata with source generator ? I couldn't find any documentation
1 replies