Oct 26 2009

Note to self

Category: fossmo @ 13:17

Remember to use a property when data binding in Windows Presentation Foundation. If you don’t remember this, you will spend at least one hour scratching your head wondering why the data won’t show up in your list box and swearing at Visual Studio 2010. But, it’s not studios fault, it’s yours!

This is wrong (field):

public List<string> MyProperty;

This is correct (property):

private List<string> _myProperty;
public List<string> MyProperty 
{ 
   get { return _myProperty; } 
   set { _myProperty = value; } 
}

I will never do this again!

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Aug 30 2009

Services

Category: DDDAdministrator @ 17:24

When starting to learn Domain Driven Design, entities and values objects are things people normally understand pretty quickly. But, when it comes to services, I feel things are a bit more unclear for many. If you ask a Domain Driven Design expert about services, you probably will get the answer; a service is something you can’t find a good place for in your domain model.

A concrete example

image

In almost every modern GUIs you use combo boxes as a way to display different choices for the user. You need a way to fill these boxes (look at the figure), but the action where you fill them doesn’t fit into your domain model in a natural way. I look at this as a service, something you need in your domain, but nothing you will force into your domain objects. In the applications I have created lately, I have often used value objects to transfer the data from the repository to the GUI through a service (follow the red arrows in the figure). You can of course create dedicated objects for this (follow the orange arrows in the figure), but I haven’t found the need for this yet.

 

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 29 2009

How to set the windows position in WPF

Category: WPF | C#fossmo @ 17:18

To position a window manually on the screen in Window Presentation Foundation you can use these system properties Window.Left and Window.Top. To get the size of the screen you can use these system properties:

System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;

To set a window (the green one) position like the one shown at the image below, you can use this method:

private void SetWindowPosition()
{
    Left = SystemParameters.PrimaryScreenWidth - (double)GetValue(WidthProperty) - 30; ;
    Top = 150;
}

image

Tags:

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 5 2009

Converting from SVG to XAML

Category: WPF | Softwarefossmo @ 19:22

To night I spent hours trying to convert from a SVG file to XAML. The reason for wanting to do the converting, is that I want a vector based image in a WPF application I’m currently developing. Using a vector based image will scale much better than using a bitmap image.

imageThe solution

I first downloaded a vector based image from this url: http://iconeden.com/icon/free/get/milky-a-free-vector-iconset
Inside the zip file you will find a SVG file. You can open this file using Adobe Illustrator, but I prefer using free alternatives, so I downloaded Inkscape. Inkscape is a open source vector graphics editor. I opened the file, and it contained several images. I wanted one of them; a clock. I copied and pasted the image into a new instance of Inkscape. If you choose Save as from the file menu in Inkscape, you will notice that I gives you the option to save as XAML. I tried doing that without success. It turned out that the XAML produced by Inkscape is not valid when opening it in Expression Blend or Visual Studio. So I saved the file as Clock.svg

On Codeplex there’s a project called XamlTune. I downloaded it and used the command prompt tool called svg2xaml.exe found in the package. The output from this small application were a XAML file called Clock.xaml. I opened this file in Visual Studio and guess what? It worked. The image were converted from SVG to XAML without any errors.

If you need to convert from SVG to XAML, I recommend that you look at this tool. I have only used it a few time, but it looks good so fare.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 2 2009

A great book to get you started with NHibernate

Category: Administrator @ 15:13

Lately I have tried to learn NHibernate. NHibernate is a object-relational-mapper. It maps data from relational databases to POCO-objects. So, what is useful about that, you may ask? Well, for a starter, it’s very handy when creating a rich domain model. If you read this blog regularly, you may know that I’m also in the process of learning Domain Driven Design.

Domain Driven Design and NHibernate

The idea behind DDD is that you focus on the domain model instead of focusing on the database or GUI when trying to capture the business value from a domain expert. If you follow the guidelines described in the books written by gurus on the topic, you will end up with a domain model that is loosely coupled from the other parts of the system you are creating. That means you don’t have a coupling against the GUI, the database or any other parts of the system. But, you still need to persist the data from the domain model to the database in some way, and this is where NHibernate comes in to play. By setting up a mapping, described in a file, from the domain model to the database you can make NHibernate do the mapping for you. How cool is that? I guess you knew that already, but the purpose of this post is not to tell you how cool NHibernate is, but to guide you in the right direction of how to start learning NHibernate.

How I learned it

image

My first approach to learning NHibernate was to look at the excellent screen casts made by Stephen A. Bohlen called Summer of NHibernate. I learned a lot from watching these screen casts, but I still felt like something were missing. It’s like when you go to a conference, at the end of the day you can’t sit down in front of the PC and start to crank out code based on what you learn that day. But, it gives you a starting point. You often get information of how to investigate the topic further. This is what Summer of NHibernate did for me and it pointed me in the direction of a book called NHibernate in action.

Beside giving you a good start on setting up and using NHibernate, it also explains how to write real-world domain models. It tells you how to set up pretty complex associations between entities and why it’s important to understand why a domain model should be persistence ignorant and so on and so fourth. If you want to have a look at the index of the book, it can be found at this link.

If you want to learn NHibernate you definitely should look at this book.

Links

Links to NHibernate resources I have used and use:

- Summer of NHibernate (screen casts)
- Dimecasts.org have some screen casts on the topic (max 10 minutes long)
- NHibernate in action (excellent book on the topic)
- NHibernate.org (You can download the binaries from this site and you find documentation)

Happy learning!

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 1 2009

My TortoiseSVN global ignore pattern

Category: source controlfossmo @ 16:32

I’m a big fan of Subversion and I love using TortoiseSVN. Many people prefer AnkSVN over TortoiseSVN because it integrates with Visual Studio, but I feel like I have more control over what’s happening when I’m using TortoiseSVN. Every time I set up a computer for development I have to add a ignore pattern to separate the files I want to check in from the ones I don’t want to check in.

This is my global ignore pattern:

*ReSharper* *.suo *resharper* *Debug* *Release* *.user *.bak

To add this pattern to TortoiseSVN follow these steps:

Right click in Explorer –> Choose TortoiseSVN –> Choose Settings –> Under ‘Global ignore pattern’ add the pattern.

 

image

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jun 2 2009

A Software Craftsman’s bookshelf

Category: Recommendations | Booksfossmo @ 14:37

I have read some books about development the last 15 years. Some I can't remember reading, but some of them have imageinfluenced how I develop  today. One of the books that pops up in my mind is Code Complete. This book really made me think of how I should develop applications. It touches on most of the subjects it's important to know about when developing; like how to debug effective, how to comment your code, how to write good loops etc.

Extreme programming
I remember working for an organization some years ago. We didn't have any senior developers working in the company, at image least seniors doing development. This resulted in a lot of code that where, well lets say, not as good as it could have been. I remember spending a lot of time in the debugger. We didn't use any development metrology. I was sure we could get a lot of benefits from following one. So I started to look into the new and hot metrology at that time; Extreme programming. The book I started reading was Extreme programming Explained. I remember trying to get the other developers to follow the practices explained in this book and I think we managed to start doing a bit of test driven development. Not long after this I changed my job, but what I read in this book stuck with me. Today I'm completely test driven!

Best practices

When I started working in the company I'm currently working for I was recommended to read a book called Ship it! This is image image a book where the writer have collected best practices from years of development. It basically describes best practices when developing, and the environment around developing efficiently. A must read for a developer. After reading this book I was really inspired and wanted to read more books in the same category, so I started image to read a book called The pragmatic programmer. If you still haven't read this book follow my link to Amazon and order it today. It's one of the most inspiring programming books a developer can read. The last year I have read some books. One of the favorite books are Clean Code. It's a good read, and I recommend it too. If I should compare it to an other book I have read, it must be Code Complete. Clean Code is a easier/faster read than Code Complete.

image Ahh..I need to remember to mention a book that describes much of the practices I follow today; Code Leader. A great book written by Patrick Cauldwell. It describes things like how to set up a  continuous integration server. How to write your build script and how to structure your development tree.


Domain Driven Design

image image image image At the customer I work for at the moment, we use Domain Driven Development. I must say I'm a big fan of capturing the requirements using DDD. There are three books I have read/browsed through on this topic. They are Domain-Driven Design: Tackling Complexity in the Heart of Software written by Eric Evans. Applying Domain-Driven Design and Patterns: With Examples in C# and .NET written by Jimmy Nilsson and .NET Domain-Driven Design with C#: Problem - Design - Solution (Programmer to Programmer) written by Tim McCarthy. I recommend reading all of this books to really understand what DDD is. I first started reading Nilssons book, and it's a great book. It uses a lot of code examples, but he often refers to Evans book, so it's a good thing to also have this book at hand. Evans book is considered the bible for DDD. I think it's a bit vague on some areas but it's a must read if you want to learn DDD. The last book, written by Tim McCarthy, is the most concrete book on the topic, and I have used many of the ideas from this book to create the application for the client I'm currently working for. If you want to get an introduction to DDD, you should take a look at the free book called Domain Driven Design Quickly. It's a summary of Evans book and is hosted at InfoQ.

SCRUM

imageI have been practicing SCRUM for a while now. The book that got me up to speed in this area, is a free book by a Swedish guy called Henrik Kinberg. The book  is called Scrum from the trenches.



This post is a response to Gørans post; A software craftsman’s bookshelf. At the end of his  post he encourage other Norwegian developers to write about their recommendations when it comes to programming books. I picked up some good tips from his post and some of the other guys he linked to.

Do you have any book recommendations for me?

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

May 28 2009

Electronic storyboards are pacifying! [Norwegian]

Category: Presentation | DND | Scrum | Speakerfossmo @ 16:19

I held a lightning talk a on a seminar a while back about electronic storyboards being pacifying. I like to share it with you. It’s in Norwegian.

Elektroniske storyboard er passifiserende from Pål Fossmo on Vimeo.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

May 19 2009

Speaking at NNUG in Trondheim 28.05.2009

Category: NNUG | DDD | Presentation | Speakerfossmo @ 14:16

image At the next Norwegian .NET User Group meeting I’m going to talk about my experience with Domain Driven Design. I hope we can get a discussion around the topic after the talk. I’m really exited and looking forward to the meeting. Sign up for the meeting here.

Tags: ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Apr 21 2009

My first experience with Domain Driven Design.

Category: DDDfossmo @ 17:33

image These last months I have been learning Domain Driven Design. It’s often shorted to DDD. I have had plans to start looking into DDD for a while, but other things have always gotten in the way. I’m working as a consultant and some months ago I was assigned to a new customer, and they wanted to use DDD in their new project. Lucky for me :-)  Now I got the change to look into this DDD stuff and I must say that it will influence how I design my applications in the future.
I find this subject extremely exiting, so I have decided to write some posts about it. Some of the subjects I will cover is Ubiquitous language, Domain Model, Entities, Value objects, Services, Aggregates, Repositories, Factories, Bounded context to list some.

How to get started

I started out my DDD journey by reading some books:

Domain-Driven Design: Tackling Complexity in the Heart of Software. This book is written by Erik Evans. It’s considered the bible of DDD. I have heard people referring to it as “Lord of the rings” for developers because it uses so many references to references to references. You know; Legolas was the son of Thranduil, King of the Woodland Realm of Northern Mirkwood, son of … you get the picture? 
I use this book more as a reference, and I haven’t read it from page to page, but I have read a book which is a summary of Evans book; Domain Driven Design Quickly. It’s a good book and only a bit over 100 pages. It’s free and can be downloaded from InfoQ.

The book to blame for me learning DDD is written by Jimmy Nilssons and is called Applying Domain-Driven Design and Patterns: With Examples in C# and .NET. It’s a great book which is easy to read and he uses a lot of examples to explain the concepts in DDD. Nilsson uses TDD through the hole book to explain what DDD is. This makes it very easy from the reader to follow.

The last book I have looked into is a book written by Tim McCharty. It’s called .NET Domain-Driven Design with C#: Problem - Design - Solution (Programmer to Programmer). This book contains a lot of code. The code can be found at Codeplex. I got some hint on how to implement some of the patterns that DDD fronts from this book.

I you find videos and podcasts more easy to learn from, I can recommend listening to Alt.NET podcast show about DDD. Scott Hanselman also have a interview with Rob Conery where the topic is DDD. The last podcast I will recommend is one from Deep fried bytes. This is a conversation with David Laribee. 

If you want more links, you should go to this site. This guy have gathered some links to different DDD sources. You can also check my delicious bookmarks for updates to links.

Ubiquitous language and domain model

The first thing that pops into my mind when someone ask me about DDD is the domain model. That’s kind of obvious because we are talking about Domain Driven Design. DDD recommends that you start out by creating a domain model before you focus on anything else. Many developers would start out by focusing on the database when they create a application. This is not recommended by DDD. The reason for this is that you want to capture the domain in a model that the business person can understand. I’m referring to business person and domain expert in this post and I’m actually talking about the same person. The business person and domain expert is often the same person or at least, the business person is the product owner and should understand the domain model. You should sit down with the domain expert and try to create a shared language; the ubiquitous language. The reason for this is that you want a language that the business person and the developer understands. By doing this you will avoid many misunderstandings. What we did when starting to figure out the domain for the customer, was to get the domain experts to write down important concepts from the business we where trying to capture. We focused on using the same terms. They didn’t, for example, use the term order, but they used sale, so we called it sale in our domain model although it looked more like an order to me.  When we had talked about the terms and how the different parts of the application should fit together, we started to mold the domain. We also created some simple sketches of parts of the domain.

The nice thing with the domain model, from a developers perspective, is that the model is the code. You don’t try to model the domain with a strange notation or tool. The code is the model. The reason we can use the code as the model, is the ubiquitous language. You are capturing requirements in terms the domain experts understands. If the domain expert is a developer, this is even simpler.

I’ll try to keep these posts short and focus at one thing at a time, so I guess this is time to end this post. Next time I will explain what a entity and a value object is.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5