Archives

Archives / 2009 / October
  • Distributing domain entities over the wire

    When we design our domain entities we don’t have a presentation layer or database in mind. The domain entities are core business objects located on the server or client side based of what kind of application we are building. Domain entities aren’t designed for distribution. When we realize that we need a distribution, we shouldn’t distribute the entities, instead collect the data we need to distribute and create a data transfer object (DTO) instead. Have the network in mind, a domain entity aren’t designed with a network in mind and of that reason not suitable for distribution. When we create our domain entities, they aren’t designed for presentation purpose, they are designed to fulfill business needs. You should be careful when you start thinking about returning a domain entity to the View when using a patterns like MVC, instead use DTO or a ViewModel, because once again the domain entities aren’t designed with presentation in mind, and aren’t often suitable for presentation purpose. It’s often better to map them to a DTO or ViewModel, objects that are suitable for presentation purpose or passed over the wire.

    Read more...

  • Some features I love in VS 2010

    This post will not be so long, I want to write a little about some Visual Studio 2010 features I love. First of all the changes made to C# is great, the default value on parameters rocks! When I implement Frameworks, I often ended up with something like this:

    public void Log(string message)

    public void Log(string message, string category)

    public void Log(string message, string category, .......)

    The last method is the one that have the most of the code, the other method with few parameters, only calls the last one, and pass null or an empty string as values to the extra arguments:

    Log(message, null, ......)

    Note: The code above is not taken from a real example, only used as pseudo code.

    Now with C# 4.0, we can instead set a default value on a argument, which will get rid of the extra methods, for example:

    public void Log(string message, string category = null, .....)

    The dynamic feature in C# is ok, but at the moment I will not use it. When we use the dynamic when we declare a varible, it will be evaluated first at runtime. It's a nice feature when we want C# to use stuff from other dynamic languages.

    dynamic something = ....

    something.Hello();

     

    Entity Framework 4.

    Will be great now when it will support POCO (Plain old clr object):

    public class Customer
    {
          public string FirstName
          {
                 get { ... }
                 set { ... }
          }
    }

    There are so many other features improvements to EF, need a new blog post for that, but the POCO support and the model first approached is better supported than the first version.

    ASP.NET AJAX 4.0

    I love the client-side binding, I have some blog post about it, so you can read about it here:

    http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx

    http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx

    http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx

    Silverlight designer

    Visual Studio 2010 have now enabled the Silverlight designer, it was not enabled in the previous Visual Studio, so we can now easier and faster create our Silverlight apps, and no need to run Expression Blend and VS at the same time.

    Improvements for web developer

    Better Java-script intellisense. Easier to add Server controls to the .aspx file. Something we need to add before was the runat="seerver" attribute, it's now directly added when we add a Server control in the source mode (not talking about to drag a control, it when we write the code).

    Code Contract

    I like design-by-contract, think everyone should read about it. We can now use code contract in our code. What I have heard, we need the VSTS version for static checking. You can read more avout Code contract here: http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx

    Read more...