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 ?
11 Replies
I'd probably use a regex source generator and some helper static class
Other than that, if you want to use DI, create some
RegexService
or whatever and register it as a singleton
Then inject it wherever neededI tried static properties and getter with lock but its kinda ugly, I will stick with singleton regex service
IMaskingPolicy is scoped so regex with MaskKeyList is initialized first and once, but its okay that list wont change often
@Cracker just use the regex source generator
I think its not available in .net 6
Then look to migrate, support runs out in November.
yep thats scheduled, cant do it in a day since huge mono app :/
Still, this feature seems useful. Will use it eventually
Just write a Python script to get all
*.csproj
files and replace net6.0
with net8.0
:when:I wish 😄
Python? Just run sed recursively.
Or that