Search This Blog

Examples

Tuesday, November 12, 2013

I would like to explain how to implement repository pattern before we proceed any further with our single page application discussion.

What is repository pattern?
Repository pattern separates the logic that retrieves the data from the database and logic that uses the data by your application. Thus it makes your data access layer independent of your presentation layer.

As shown in above figure:

Create database table

Create POCO class (Model class) with getters and setters mapping to all the properties of database table.

Create Interface which list down all the operations we are going to perform on that table. Most of the time we are doing CRUD operation (Create, Read, Update and Delete operation on table).

Implementation of Interface.

Presentation layer consuming interface to perform database operation.

In summary, accessing database through interface is repository pattern. (Disclaimers: Please note I am using few sentence which are very lame in nature just to make explanation as simple as possible for anyone to understand, ones user have good understanding he can judge the things better himself).

Advantages of making use of Repository Pattern

Since we are accessing database through interface, presentation layer is independent of database layer. That means you can have same data access logic reusable for multiple presentation layer (eg: console application, asp.net mvc, asp.net web form or windows form can use same data access logic.) Similarly whenever you change the way you access data from database doesn't affect how it is rendered on presentation layer. That means if you are using ado.net to access database, later you decide to make use of entity framework or micro-orm or web service or web api, will not require you to make any change on the presentation side.

Code will be more maintainable and readable.

Testable code.

Flexibility of architecture and much more (Running out of time, so google it please).

Monday, November 11, 2013

Like any other application HTS is not following default route of having Global.asax as starting point. "I believe" this is not good and there are few other things which "I believe" you won't do it for your production code which we will be going to customize in upcoming blog post.

Flow of process for Hot Towel SPA template

App_Start/BreezeWebApiConfig.cs/RegisterBreezePreStart()

App_Start/HotTowelRouteConfig.cs/RegisterHotTowelPreStart()

Root/Global.asax/Application_Start()

App_Start/FilterConfig.cs/RegisterGlobalFilters()

App_Start/RouteConfig.cs/RegisterRoutes()

App_Start/HotTowelConfig.cs/PreStart()

Controllers/HotTowelController.cs/Index()

Views/HotTowel/Index.cshtml

App/Main.js/boot()

App/Shell.js/boot()

App/Home.js/activate()

Understanding of above process will be very helpful in customizing Hot Towel SPA template to suits your needs.

Situation where above process flow is very helpful

Customizing Application specific settings

Remove breeze and adding support for web api

Adding any more JS support.

In next post we will understand how to customize hot towel spa to suits your custom needs.

Step 3: Ones your solution is ready, you will notice all SPA related files in App folder. You will also notice that Hot Towel SPA (HTS) has taken care of initial plumbing of installing durandal.js, require.js, bootstrap, breeze, etc.

App Folder Stucture

Views Folder - Contains HTML files, it will have plain html code which is used for presentation.

For those of you haven't got chance to work on Single Page Application (SPA), I will be discussing few of my learning in series of post, including how to perform CRUD operation using both Breeze and Web Api.

What is Single Page Application (SPA)?
(From Asp.net Site) ASP.NET Single Page Application (SPA) helps you build applications that include significant client-side interactions using HTML 5, CSS 3 and JavaScript. It’s now easier than ever before to getting started writing highly interactive web applications.

In my own words:

SPA application doesn't requires page postback.

SPA application works very well with web api and it can be used for good user experience (UX).

SPA application doesn't mean that, their will be only single page in your application. It will be multipage application which doesn't requires postback

From developers point of view, SPA is javascript way of doing MVC, when working with VS.Net and asp.net mvc.

SPA technology is not new but with KnockoutJS and other javascript framework now making SPA application will be much more easier than few years back.

VS.Net comes with default SPA template when you install VS.Net 2012.2 update. However I will highly recommend using John papa's Hot Towel SPA template since it comes up with initial plumbing work for you so that you are get, set, go to develop SPA application.

Since John is stressing more on using breeze to make DB call, which "I believe" is not good, since it is very hard to implement "Repository Pattern" and I don't like javascript files spreading across multiple project is good. Instead "I believe" the best way to go with SPA is make use of Hot towel SPA and take out breeze related stuff from project and hook up web api related plumbing. Since Web api calls are not javascript dependent we can easily spread our code across multiple solution without including javascript file and can do whatever we like. (Specially it is very easy to implement repository pattern in SPA using Web api rather than using Breeze.)

My views on Breeze Vs Web Api

I personally find it is very easy and fast to develop SPA application using Breeze and it is easy to do client side caching of data.

Web api is best way to work with SPA since you are not dependent on javascript plumbing to do DB call.

If you are not sure about which route to go, I would recommend you to try implementing Repository Pattern with both Breeze and Web Api and it will make your decision simple.

In my whole series I will be making use of Hot Towel SPA Template to create all application.

Most of the time when you are working on SPA, if you run into problem. Search appropriately to get quicker solution: For example: If you are facing problem in data binding then search for "Knockout" rather than "Hot towel spa" or "SPA". Similarly if you run into problem for navigation then search for "Durandal", If you are running into problem for CSS search for "Bootstrap" and so on.

In chrome go to settings at the right end corner and select Disable cache (while Dev Tools is open)

Make use of "Internet Explorer (IE) while working with VS.Net" if you are facing trouble while debugging javascript file. Javascript debugging works very well when we are working with IE and VS.Net

Master concept of Knockout.Js and Web Api. On High level SPA is all about using Knockout.Js and Web api (Please note: I am assuming here that user will be using Hot Towel SPA template and using all combination as describe above)

In next post we will create our first SPA application using Hot towel spa template.

Saturday, November 09, 2013

NotMapped Property for PetaPoco or Ignore Column while Insert/Update in Petapoco[NotMapped] ==> [ResultColumn][NotMapped] equivalent of entity framework in Petapoco is [ResultColumn]For more information

Example: If you have contact form model where you want user to enter captcha, but you don't want this captcha to be store in db, so In order to ignore captcha column while inserting values in database you can mark the column as [NotMapped] in entity framework and if you are using Petapoco you can use attribute [ResultColumn]

Most Recent Post

Community Updates

Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.