Source Code Generation using Razor Template Engine for Both Client Side and Server Side

Automating Source code generation can be surprisingly easy and will reap major benefits. It will help you develop 90% of the API’s for any project in just a button click. The primary benefits of automating source code generation are shown below in the form of a Bar chart.

Razor Template Engine

Explanation

Creating dynamic source code (Controller, facade, and Dao including interfaces) using code templates and razor template engine.

Steps to be followed to generate controller code are as follows

1. Create a controller template and keep only the common operations. Rename the file with extension as .txt.

2. Inside the file, where ever the Entity name is there replace it with razor template code (@Model.Entity). Assume Entity is your “table name” which will be given as  input parameter in reality.

3. Create a model object of dynamic type (refer email sending template in our solution)

4. Then bind data in the template like

var result = Utilities.BindDataInTemplate(template, “reg-email”, input.User as Object); Here BindDataInTemplate functions which is written in utilities file, binds the data in the template.

5. Save the result string as “.CS” Controller.cs.

The above similar steps are followed to generate other source code (facade and Dao including interfaces).

Details of API to generate server side dynamic source code 

API URL : http://localhost:53154/api/controller/create

Method Type : POST

Request :

{

"Entity": "Table name",

"Author": "User name";

}

 

Details of API to generate client side dynamic source code 

(simple html,route.js,module.js,controller.js,service.js)

API URL : http://localhost:53154/api/controller/create/js

Method Type : POST

Request :

{

"Entity": "Table name",

"Author": "User name",

"ControllerDescription" : "Description for Controller.js"

"ServiceDescription"    : "Description for Service.js"

"FilePath"              : "FilePath (Example: "E: Angulartemplate")";

}

  

Reference : Please refer trick#2 in the below link for using code templates and razor template engine

http://odetocode.com/blogs/scott/archive/2013/01/09/ten-tricks-for-razor-views.aspx.

Conclusion

Reliability, availability, productivity, performance, and cost reduction are powerful arguments for adopting automation solution. It helps you to create over 90% of the API’s that are required for an application. However, the tool generates code for API’s with common operations i.e. Save/Update, GetById, GetAll, Search, Search with Pagination and Delete. The API’s which are specific to the application should be taken care.

 

FacebookTwitterGoogle+Share
Deploy Applications to AWS Cloud in a Jiffy!

Amazon Web Services (AWS) is the most favored cloud provider for Dot Net developers because of its flexibility, scalability, and reliability. It is a cost-effective computing resource solution that is designed to assist application developers to host their applications quickly and securely. AWS helps businesses to reduce capital expenses and administrative costs and retains the security, performance, and reliability requirements your business demands.

Here, I have provided a detailed step by step procedure for deploying your applications to AWS cloud. Before moving to the procedure, check out the basic prerequisites.

Pre-requisite

Steps to Deploy

#1. Open your application using Visual Studio. Click Build from the menu and select Publish to AWS.

AWS Deployment

#2. Once you click on the Publish to AWS, a popup screen will open as shown below.

AWS Deployment

#3. Select the account profile if it is already created or create a new profile. To create a new profile, click on the Profile icon. A popup screen will display as shown below.

AWS Deployment

#4. You can get the account ID and the Key information from AWS management console. Click Account Identifiers to get account ID and Access Keys to get the Key information. Fill in all the fields for profile creation and click OK.

AWS Deployment

#5. If you are deploying first time, chooseCreate a new environment under deployment target. Also, choose your required Region for deployment. Click Next to proceed further.

AWS Deployment

#6. Select the environment tag and enter the details to create a new environment. Check the availability of your URL, and if it exists, modify URL to a different name. Click Next to proceed.

AWS Deployment

#7. Configure the environment as per the requirement and click Next.

AWS Deployment

#8. Select service roles granting permissions to your application and click Next.

AWS Deployment

#9. Specify the build configuration, app pool runtime, and app path.

AWS Deployment

AWS Deployment

#10. Review the environment configuration and click Deploy to start the deployment.

AWS Deployment

#11. The deployment event details will be shown in your visual studio window as shown below.

AWS Deployment

Now click on the URL shown after the successful deployment.

Conclusion

Migrating applications to AWS cloud is simple and fast as mentioned above. Whether it is an existing application or a new SaaS-based application, AWS eases the migration process and helps dramatically increase both the effectiveness and efficiency of your business process.