Exemplo n.º 1
0
        public RazorMailMessageFactory(ITemplateResolver templateResolver, Type templateBase, Func <Type, object> dependencyResolver, ITemplateCache templateCache)
        {
            if (templateResolver == null)
            {
                throw new ArgumentNullException("templateResolver");
            }
            if (templateCache == null)
            {
                throw new ArgumentNullException("templateCache");
            }
            if (templateBase == null)
            {
                throw new ArgumentNullException("templateBase");
            }

            _templateResolver = templateResolver;
            _templateCache    = templateCache;

            var templateServiceConfiguration = new TemplateServiceConfiguration
            {
                // Layout resolver for razor engine
                // Once resolved, the layout will be cached by the razor engine, so the resolver is called only once during the lifetime of this factory
                // However, we want the ability to cache the layout even when the factory is instatiated multiple times
                Resolver = new DelegateTemplateResolver(layoutName =>
                {
                    var layout = _templateCache.Get(layoutName);

                    if (layout == null)
                    {
                        layout = _templateResolver.ResolveLayout(layoutName);
                        _templateCache.Add(layoutName, layout);
                    }
                    return(layout);
                }),

                // Set view base class
                BaseTemplateType = templateBase
            };

            if (dependencyResolver != null)
            {
                templateServiceConfiguration.Activator = new Activators.Activator(dependencyResolver);
            }

            _templateService = new TemplateService(templateServiceConfiguration);
        }
Exemplo n.º 2
0
 public RazorMailMessageFactory(ITemplateResolver templateResolver, Type templateBase) : this(templateResolver, templateBase, null, new InMemoryTemplateCache())
 {
 }
Exemplo n.º 3
0
 public RazorMailMessageFactory(ITemplateResolver templateResolver, Type templateBase, Func <Type, object> dependencyResolver) : this(templateResolver, templateBase, dependencyResolver, new InMemoryTemplateCache())
 {
 }
Exemplo n.º 4
0
 public RazorMailMessageFactory(ITemplateResolver templateResolver) : this(templateResolver, typeof(DefaultTemplateBase <>), null, new InMemoryTemplateCache())
 {
 }