Razor.SetTemplateBase Missing

Jan 12, 2012 at 3:14 PM
Edited Jan 12, 2012 at 3:16 PM

The documentation refers to a static method off of Razor called "SetTemplateBase" that doesn't seem to exist in version (the latest version published to NuGet).

Looking at the API, the only thing I can figure out is that I need to use the SetTemplateService method as the alternative, but it's not 100% clear how to use that to do the same thing.

Any assistance would be appreciated.

Jan 31, 2012 at 8:02 PM

I just had the same problem and this was my workaround:

var tplCfg = new RazorEngine.Configuration.TemplateServiceConfiguration();
tplCfg.BaseTemplateType = typeof(CustomTpl);
var tplSvc = new TemplateService(tplCfg);

 It seems to work the way the docs specify.

Feb 1, 2012 at 3:13 PM


The configuration mechanism provided for v2.x wasn't flexible enough to support multi-threaded scenarios and has been reworked for the upcoming v3 release. Updated documentation at the Github site (https://github.com/Antaris/RazorEngine) will reflect these changes, but currently it is unfinished.

The method dtanders has detailed is the correct way, so creating a configuration instance to initialise the service with the base type is the way to go.

You don't need to use the Razor static type, if you prefer using instance services, you can do something like:

var config = new TemplateServiceConfiguration
    BaseTemplateType = typeof(MyTemplateBase<>)

using (var service = new TemplateService(config))
    // Use template service.
I will be extending the fluent configuration mechanism to support base template types also.