These are chat archives for Antaris/RazorEngine

2nd
Jun 2015
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 13:00
Hi all
Do anybody know how to use RazorEngineService with already compiled views?
There was TemplateService in RazorEngine 3
and i just do something like this
http://codepaste.net/wui5r7
but now TemplateService is obsolet
and produce exception on Run method
any help please...
Matthias Dittrich
@matthid
Jun 02 2015 14:01

Yes that's by design: There are really two points here: First is template instance creation, we don't allow it as we might need to save some internal state and therefore don't want to provide an API for it (note you still can define your own type if you need to!)

The other thing is re-using ITemplate instances: We don't allow that anymore for multiple reasons. First its not thread safe and second re-using is really error prone.

There is in fact a bug in your code: nested templates (layouts or includes) are not cached properly but recompiled more than actually required...

Therefore I recommend to not use RazorEngine with the legacy API and instead use the new API (sometimes you need to do/think a bit more, but its for the greater good :)

Do you compile the templates and add them as resources? You can still make that work with a custom caching provider...
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:01
yep with new api i found that paradigm is changed
so i have to implement custom CachingProvider and TemplateManager
also ITemplateKey ITemplateSource and ICompiledTemplate
that is so huge overenginiring for reuse ready templates
Matthias Dittrich
@matthid
Jun 02 2015 15:03
Yeah that should work
On the other hand nothing changes on the usage side...
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:03
"Do you compile the templates and add them as resources?" exctly
*exactly :)
Matthias Dittrich
@matthid
Jun 02 2015 15:04
Sounds really interesting, is that part of your build?
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:04
probably part of application
we generate source via razor temapltes
sorry for misspell
that razor templates already complied with RazorGenerator tool
Matthias Dittrich
@matthid
Jun 02 2015 15:06
well yes it looks over engineered, but on the other hand you could provide your implementations and other people can use it without changing their usage code (only the setup/config), which is a good thing considering the complexity here.
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:06
good point
thanks
Matthias Dittrich
@matthid
Jun 02 2015 15:07
and again getting it work bug-free without pitfalls by using ITemplate is almost impossible ;)
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:08
than can toy suggest something else?
*you = toy
Matthias Dittrich
@matthid
Jun 02 2015 15:08
what you do now (using the interfaces) should work
*new interfaces
If you run into problems feel free to ask here and wait for an answer or open a new issue on github
Vladimir Shmidt
@vladimir-shmidt
Jun 02 2015 15:10
ok try to do and maybe try to request changes :)
Matthias Dittrich
@matthid
Jun 02 2015 15:14
Sure. Btw generating the templates as part of the build and including them as resources sounds like a really nice idea! If there is a chance to contribute this back I would gladly help with the integration part, I think quite some people would like to have this :) (as part of RazorEngine or a separate NuGet package)