Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Matthias Dittrich
@matthid
Just changed the license to Apache2!
This is now released in https://www.nuget.org/packages/RazorEngine/3.7.0-beta1. Please test and report if I broke anything.
Richard Bogle
@Boggin
@matthid I found out it wasn't the VS2010 compiler - it was me trying to pass an int to the 'name' parameter. I fixed it by putting the argument names against each parameter and also reading through the large number of overloads then calling .ToString() on the one that was incorrect. So, no need to up date your documentation.
Matthias Dittrich
@matthid
Good to know, thanks
Brett Baggott
@BrettBaggott
I posted about this on the Google Group but thought I should post it here as well. So if I understand correctly, the now obsolete Parse is, potentially, creating an assembly per request (since there is no accomodation for caching, etc.)
Matthias Dittrich
@matthid
You shouldn't use obsolete API if you don't need to. To answer your question: It depends on the overload and version you are using..
Brett Baggott
@BrettBaggott
Version 3.4.1 and called like so: var html = Razor.Parse(page.Content.Value);
where page.Content.Value is a snippet of Razor syntax pulled from data
I understand we shouldn't use obsolete API, this is adopted code and I want to follow the process outlined in your Upgrading to 3.5.0, but I'm being told "what we have now is good enough, we might get to that later". Problem is, this is yet to be deployed to production code. It will be replacing a website that sees about 2 million pageviews per month, and the bulk of those we be delivered via that Parse call.
Brett Baggott
@BrettBaggott
So if I'm reading everything right, that particular way of calling the API will generate an assembly per request (barring any other caching mechanisms such as output cache)
Matthias Dittrich
@matthid
Yes you should at least use an overload with a name/cachename parameter to get some kind of caching...

It should actually be quite easy to see (even while debugging) if caching is in place. First its just very slow when everything is compiled, and second you can see a "csc.exe" in task manager whenever a template is compiled (which should be the one time only for every template)

Does this answer your question?

ABerg
@ABergBN
@matthid First of all great project. Thank you for that. But I have a problem, I don't know if its a bug or not. If use the deprecated TemplateService, I can Compile my templates with utf8, but if I use the suggested RazorEngineService, I get a not properly compiled template for characters like 'ä', 'ü' and so on. If you need more informations I can send you my code.
Matthias Dittrich
@matthid
@ABergBN I tried to reproduce but it seems to be working for me. A repro (for example a unit test) would be perfect. Actually the deprecated API is calling the new API internally, so it has to work somehow...
ABerg
@ABergBN
@matthid I sent you an email, with an example. It's a simple console application.
Matthias Dittrich
@matthid
@ABergBN Sorry I cannot find that mail, can you tell me to which address you sent it or try to send it again?
Matthias Dittrich
@matthid
nevermind, found it :)
I briefly looked at it: The problem is that the cshtml file is not saved with proper UTF8 encoding. So either save it via UTF8 or load it with the proper encoding.
ABerg
@ABergBN
Thanks! I loaded it with UTF8 Encoding in my ITemplateManager, but now I changed the encoding in my cshtml file and now everything works fine, thanks!
seriouz
@seriouz
Hey i want to use RazerEngine for templating hundreds of html elements like inputs, dropdowns, checkboxes etc... Is a custom implementation of the ICachingProvider the best way to go?
Matthias Dittrich
@matthid
It doesn't really depend on the size of the templates, but more on your (performance, memory) requirements and the number of your templates...
seriouz
@seriouz
there will be 20 template files (one foreach html-element) performance and memory is high (azure cloud hosted)
Matthias Dittrich
@matthid
I would recommend the default settings and use your own when you run into problems
seriouz
@seriouz
Easy use of:
string result = Engine.Razor.RunCompile(template, "input", typeof(Input), inputEl);
string result = Engine.Razor.RunCompile(template, "input", typeof(Input), inputEl2);
string result = Engine.Razor.RunCompile(template, "select", typeof(Select), selectEl);
Is the Engine.Razor. threadsafe? In my enviroment it is possible, that *Engine.Razor.RunCompile(template, "input", typeof(Input), inputEl) is called at the same time.
Matthias Dittrich
@matthid
Basically "yes", we always create a new template instance for every "Run"
If you run into any issue open one on github
seriouz
@seriouz
Okay :) I'll test is the next days (Mass compile ;>)
*it
Any idea if its possible to join this chat via IRC or similiar?
such wow... so style ... wow => https://irc.gitter.im/
Matthias Dittrich
@matthid
yeah gitter is nice :D I love all the integrations they provide :)
seriouz
@seriouz
hi from irc
Matthias Dittrich
@matthid
it seems to work! I gotta go now. Report back if your testing works ;)
seriouz
@seriouz
I#LL do! good night!
Vladimir Shmidt
@vladimir-shmidt
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

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
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
Yeah that should work
On the other hand nothing changes on the usage side...
Vladimir Shmidt
@vladimir-shmidt
"Do you compile the templates and add them as resources?" exctly
*exactly :)