Cleaning after Knockout

יום שלישי, ינואר 29, 2013

Using KnockoutJS is really fun. You set some data-bind attributes on your HTML and KnockoutJS does the magic of binding it to a JavaScript object (A.K.A, view model) An important fact that most of us are missing is that Knockout holds some internal data structure to manage its magic. Basically, every time you call ko.applyBindings a new management record is added to KO internal representation. This means that your view model is being held by some global data managed by KO. So in case you create and destroy HTML dynamically using JavaScript the view model is...

Are you using Cassette?

יום שלישי, מרץ 20, 2012

ASP.NET 4.5 Developer Preview introduces a new capability to manage scripts bundling and minification. You can read about it here. However, the current implementation lacks a very important aspect of scripts management which is managing the dependencies. As you know, when referencing a single script file you also need to reference all its dependencies. Wouldn't it be nice if someone automatically injects the right dependencies? Enter Cassette world ... Cassette is an HttpModule which seats inside ASP.NET pipeline and monitors requests for scripts and CSS. Cassette can automatically bundle and minify your code and even more interesting it can parse each...

Implement an HTML table using DIVs

יום שבת, דצמבר 24, 2011

This is quite an old topic but still when browsing through some popular forums I still encounter the following question: "How can I implement a table using DIVs and control the width of each column?" Before digging into the implementation I would like to share my thoughts regarding the old TABLE vs. DIV war:In the old days web developers used TABLE tag for displaying a tabular data and for controlling the layout of the page.These days it seems as everyone hates TABLE and tries to use DIV instead for both tasks. I don't share the same feelings.I use TABLE for tabular...

Exclude A Filter

יום שישי, אוקטובר 28, 2011

In my last ASP.NET MVC MSDN session I was asked a simple question: "How can we disable a filter for a specific action, assuming it is already defined at the class level?" Of course, having this ability can really ease the maintenance of our application. Without this ability we need NOT to define the filter at the class level and then define at each action level. Well, I did not have any simple question. However, I claimed that such an infrastructure can be easily developed using the excellent ASP.NET MVC extensibility support. Is that so? Let's try do it Full sample code...


יום רביעי, ספטמבר 28, 2011

Two days ago I delivered another ASP.NET MVC 3 MSDN session.As usual, we started with the basics to allow engineers not familiar with ASP.NET MVC to understand the major concepts behind it During the second part of the session, I demonstrated several subjects that are considered more advanced such as, Custom Action Result, Custom Model Binder, Custom Metadata Provider and other Custom XXXIn addition, I had the chance to introduce some really nice tools such as Knapsack and ASP.NET Mini Profiler All samples which were presented during the session can be found at my SkyDrive public folders I really enjoyed delivering this...

Source Control with SVN

יום שישי, אפריל 22, 2011

Since 2005 I've been mostly working with Microsoft Team Foundation Server to manage my source code. Before that I had the chance to work with Microsoft Source Safe and even a bit with WinCVS (for self projects) These days I am back again working on a self project and need to share my source code with two other developers. All roads led me to SVN.I was quite surprised how easily an SVN server can be installed and manipulated from Windows Explorer. So I decided to share this info with you. There are several implementations of SVN server you can use. I...

Implementing Composite Pattern with Entity Framework Code First – Part 2

יום חמישי, מרץ 17, 2011

In my previous blog post I described the way you can implement Composite pattern using Entity Framework Code First. The sample uses EFCodeFirst CTP 5 which suffers from a minor bug related to the composite relationship. Microsoft just released EF 4.1 RC which fixes the issue. Now, you can implement your composite pattern in a clean fashion. You can find the fixed composite pattern sample here.  

Implementing Composite Pattern with Entity Framework Code First

יום רביעי, מרץ 2, 2011

The full sample code can be downloaded here Entity Framework allows us to map object relationships into a database. One of the useful relationship is the Composite Pattern. Suppose we have implemented the following class diagram: As you can see this is a classical implementation of the Composite design pattern, where Group holds a collection of polymorphic items through the property Items of type BookItem. We would like to save this model into a database using Entity Framework Code First.According to ECCodeFirst coding convention guidelines we should define the following classes:public abstract class BookItem {     public int ID { get; set; }     public virtual Group Parent { get; set; }     public abstract void Accept(IBookVisitor visitor); } public class Group : BookItem {     public string Name { get; set; }     public virtual ICollection<BookItem> Items { get; set; }     public Group()     {         this.Items = new List<BookItem>();     }     public override void Accept(IBookVisitor visitor) {...} } public class Person : BookItem {     public string FirstName { get; set; }     public string LastName { get; set; }     public virtual ICollection<Address> Addresses { get; set; }     public Person()     {         this.Addresses = new List<Address>();     }     public override void Accept(IBookVisitor visitor) {...} } public class Address {     public int ID { get; set; }     public string Value { get; set; }     public string Description { get; set; }     public virtual Person Parent { get; set; }     public int PersonID { get; set; }     public void Accept(IBookVisitor visitor) {...} } public class BookContext : DbContext {     public DbSet<BookItem> Items { get; set; }     public BookContext()         : base("AddressBook")     { }     protected override void OnModelCreating(ModelBuilder model)     {         model.Entity<BookItem>().ToTable("BookItems");         model.Entity<Person>().ToTable("Persons");         model.Entity<Group>().ToTable("Groups");         model.Entity<Address>().HasRequired(a => a.Parent) ...

MSDN Session – Introducing ASP.NET MVC

יום רביעי, פברואר 23, 2011

Yesterday I delivered a nice (hopefully) MSDN session at Microsoft. During the session I presented the main features/goodies that were released during January month as part of ASP.NET MVC 3 release. The session was 4 hours long and was quite intense. During the first part of the session I built an application from scratch adding at each step a new functionality like editing capabilities, controlling access and routing system manipulation.During the second part I introduced the new features of ASP.NET MVC 3 and related technologies. Specifically I talked about: Razor syntax NuGet IIS Express Entity Framework Code First ASP.NET MVC 3 specific enhancements  Many participants...