Browse Source
Merge pull request #1252 from colinin/fix-dynamic-template
fix(text-template): Fix the rendering error of the text content
pull/1267/head
yx lin
8 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
14 additions and
3 deletions
-
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentContributor.cs
-
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentProvider.cs
-
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateDefinitionInitializer.cs
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
@ -42,6 +43,12 @@ public class TextTemplateContentContributor : ITemplateContentContributor, ITran |
|
|
|
var repository = context.ServiceProvider.GetRequiredService<ITextTemplateRepository>(); |
|
|
|
var template = await repository.FindByNameAsync(context.TemplateDefinition.Name, culture); |
|
|
|
|
|
|
|
// 2025/06/23 fixed 非内联本地化模板内容为空时,回退到默认文化
|
|
|
|
if (template == null && !culture.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
template = await repository.FindByNameAsync(context.TemplateDefinition.Name, context.TemplateDefinition.DefaultCultureName); |
|
|
|
} |
|
|
|
|
|
|
|
return new TextTemplateContentCacheItem( |
|
|
|
template?.Name, |
|
|
|
template?.Content, |
|
|
|
|
|
|
|
@ -30,8 +30,12 @@ public class TextTemplateContentProvider : TemplateContentProvider, ITransientDe |
|
|
|
bool tryDefaults = true, |
|
|
|
bool useCurrentCultureIfCultureNameIsNull = true) |
|
|
|
{ |
|
|
|
var template = await TemplateDefinitionStore.GetAsync(templateName); |
|
|
|
var template = await TemplateDefinitionStore.GetOrNullAsync(templateName); |
|
|
|
if (template != null) |
|
|
|
{ |
|
|
|
return await GetContentOrNullAsync(template, cultureName); |
|
|
|
} |
|
|
|
|
|
|
|
return await GetContentOrNullAsync(template, cultureName); |
|
|
|
return await base.GetContentOrNullAsync(templateName, cultureName, tryDefaults, useCurrentCultureIfCultureNameIsNull); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -36,7 +36,7 @@ public class TextTemplateDefinitionInitializer : ITransientDependency |
|
|
|
using var scope = RootServiceProvider.CreateScope(); |
|
|
|
var applicationLifetime = scope.ServiceProvider.GetService<IHostApplicationLifetime>(); |
|
|
|
var token = applicationLifetime?.ApplicationStopping ?? cancellationToken; |
|
|
|
using (CancellationTokenProvider.Use(cancellationToken)) |
|
|
|
using (CancellationTokenProvider.Use(token)) |
|
|
|
{ |
|
|
|
if (CancellationTokenProvider.Token.IsCancellationRequested) |
|
|
|
{ |
|
|
|
|