Example #1
0
        public static IMvcBuilder AddTemplate(this IMvcBuilder self)
        {
            self.Services
                .AddSingleton<TemplateCollection>()
                .AddSingleton<IRazorViewEngine, TemplateEngine>()
                .AddScoped<Template>();

            return self.AddViewOptions(x =>
            {
                foreach (var v in x.ViewEngines)
                    if (!(v is TemplateEngine))
                        x.ViewEngines.Remove(v);
            });
        }
        public static IMvcBuilder AddMultiTemplateEngine(this IMvcBuilder self)
        {
            self.Services
                .AddContextAccessor()
                .AddSingleton<TemplateCollection>()
                .AddSingleton<IRazorViewEngine, MultiTemplateEngine>()
                .AddScoped<TemplateManager>();

            return self.AddViewOptions(x =>
            {
                foreach (var v in x.ViewEngines)
                    if (!(v is MultiTemplateEngine))
                        x.ViewEngines.Remove(v);
            });
        }