asp.net MVC example Project "Suteki.shop" Analysis of nvelocity templates engine

Source: Internet
Author: User

The nveloctiy template engine is used in Suteki.shop to provide a customized message template. And the function of the mail is when the order status changes, the system will send the buyer mail notification. The content of the mail message is customized using the nveloctiy template (. vm extension).

Because the latest source package in Sutekie.shop only partially implements its functionality, and all features are still being perfected, to run the functionality described in this article, you need to download its latest Program files (including unit test files) in the link address below:

http://code.google.com/p/sutekishop/source/detail?r=282

The files to download include:

/branches/JtG_Enhancements/Suteki.Shop/Suteki.Shop/Views/EmailTemplates/OrderC onfirmation.vm 
/branches/JtG_Enhancements/Suteki.Shop/Suteki.Shop/Views/EmailTemplates/OrderDispatch.vm   
/branches/JtG_Enhancements/Suteki.Shop/Suteki.Shop/Views/EmailTemplates/_orderDetails.vm< br />/branches/JtG_Enhancements/Suteki.Shop/Suteki.Shop/Controllers/OrderStatusController.cs   
/branches/JtG_Enhancements/Suteki.Shop/Suteki.Shop/Services/EmailService.cs 

Wait a minute.

After downloading and overwriting (or adding) to the local project, we also need to register the corresponding Emailbuilder component in the Castle Windsor. We just open the Containerbuilder class and find its Build method (Suteki.shop\containerbuilder.cs) and add the following code:

Component.for<iemailservice> (). Implementedby<emailservice> (). Lifestyle.singleton

Note: I have introduced the content of the IOC on Castle Windsor in this article.

The final code looks like this:


Container. Register (
Component.for<iunitofworkmanager> (). Implementedby<linqtosqlunitofworkmanager> (). Lifestyle.transient,
Component.for<iformsauthentication> (). Implementedby<formsauthenticationwrapper> (),
Component.for<iservicelocator> (). Instance (new Windsorservicelocator (container)),
Component.for<authenticatefilter> (). Lifestyle.transient,
Component.for<unitofworkfilter> (). Lifestyle.transient,
Component.for<databinder> (). Lifestyle.transient,
Component.for<loadusingfilter> (). Lifestyle.transient,
Component.for<currentbasketbinder> (). Lifestyle.transient,
Component.for<productbinder> (). Lifestyle.transient,
Component.for<orderbinder> (). Lifestyle.transient,
Component.for<iordersearchservice> (). Implementedby<ordersearchservice> (). Lifestyle.transient,
Component.for<iemailbuilder> (). Implementedby<emailbuilder> (). Lifestyle.singleton,
Component.for<iemailservice> (). Implementedby<emailservice> (). Lifestyle.singleton//Newly added code
);

Once we have done this, we can compile and run the project.

Let's take a look at today's protagonist Emailbuilder, which implements the work of loading template information using Nvelocityengine and binding the data in ViewData to a specified variable in the template. Here's the class diagram:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.