Support in Net Core Asp.Net #472
-
I am using SmartFormat in Net Core AspNet project. I have own extension that I register it on startup globally: But ThreadStaticAttribute on Smart.Default prevents from reliably registering extensions globally as for each new thread my extension is not available because Smart.Default is newly created. Is there some workaround, where I can set extension globally and it is picked up whenever CreateDefaultSmartFormat is called? Maybe like SmartSettings.AddDefaultExtensions and those extension will be added on each new thread... |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
With AspNet Core and services.AddTransient<SmartFormatter>(sp =>
{
var smart = new SmartFormatter(new SmartSettings {
// Configure the SmartSettings here if needed
});
// Configure the SmartFormatter here if needed
smart.AddExtensions(SmartFormat.Extensions.GlobalVariablesSource.Instance);
return smart;
}); The upcoming |
Beta Was this translation helpful? Give feedback.
-
Yes, I know I can use DI, but then I would have to declare it on every controller, pass it to services etc... It is easier as static :-) So, upcoming SmartFormat will be thread safe, so it will not be generated with each thread? |
Beta Was this translation helpful? Give feedback.
-
Just tried 3.6.0 and it works. Tested in ASP.NET Core. I just add extensions on startup and I do not need to readd it for each thread. Thanks |
Beta Was this translation helpful? Give feedback.
With AspNet Core and
SmartFormat 3.5.3
you could provide the configured formatter for DI like this:The upcoming
SmartFormat 3.6
aims to be thread-safe, so it could be added as singleton.