using System; using System.Collections.Generic; using System.Threading.Tasks; using EventHub.Options; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.TextTemplating; using Volo.Abp.TextTemplating.Scriban; namespace EventHub.Emailing { [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] [ExposeServices(typeof(ScribanTemplateRenderingEngine), typeof(EventHubEmailTemplateRenderingEngine))] public class EventHubEmailTemplateRenderingEngine : ScribanTemplateRenderingEngine { private readonly EventHubUrlOptions _options; public EventHubEmailTemplateRenderingEngine( ITemplateDefinitionManager templateDefinitionManager, ITemplateContentProvider templateContentProvider, IStringLocalizerFactory stringLocalizerFactory, IOptions options ) : base( templateDefinitionManager, templateContentProvider, stringLocalizerFactory) { _options = options.Value; } public override async Task RenderAsync( [NotNull] string templateName, [CanBeNull] object model = null, [CanBeNull] string cultureName = null, [CanBeNull] Dictionary globalContext = null) { if (globalContext == null) { globalContext = new Dictionary(); } globalContext["current_year"] = DateTime.Today.Year; globalContext["app_url"] = _options.Www; return await base.RenderAsync(templateName, model, cultureName, globalContext); } } }