Sep 24 2011

Talking at Norwegian .NET User Group next thursday

Category: CQRS | Database | DDD | WPFfossmo @ 09:49

The last three years I have been working for a customer in Trondheim, Norway, building a application based on Windows Presentation Foundation (yeah, I know it's not the hottest stuff), SQL Server, Entity Framework 4.1 (Code first) and a cool scalable architecture. At the user group meeting I will present how we buildt the architecture and how we solved the problems around scalability. I'm looking forward to presenting this stuff for the user group and hope to see you there!!

Sign up for the meeting at http://www.nnug.no/Avdelinger/Trondheim/Moter/NNUG-Trondheim---29-september-2011/ 

Tags: ,

Currently rated 1.5 by 248 people

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

Oct 26 2010

How to set up spaces in Vim?

Category: VIMfossmo @ 17:30

To use spaces instead of tabs in VIM, add these lines to your .vimrc file:

set tabstop=3

set shiftwidth=3

set expandtab

Tags:

Currently rated 3.0 by 10 people

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

May 19 2010

WCF Data Services: A perfect fit for our CQRS implementation

Category: CQRSfossmo @ 15:47

When we started implementing CQRS architecture in the project I'm working on at the moment, we used NHibernate to get the data from the database on the query side and to the view model in the GUI. This worked fine, but it took a bit of time to implement what was needed to get the data through “all” the layers and to the GUI. It was tedious and error prone.

We started to look for other ways to do this. We considered using plain SQL through ADO.NET, but we wanted something that was simpler and faster to implement. By using ADO.NET we still had to create web services and do a bit of mapping. WCF Data Services ended up being our “savior”.

A quick update on WCF Data Services

WCF Data Services is built upon the open data protocol (OData), and OData is built upon the atompub protocol. OData is developed at Microsoft, but published as a open standard. You can read more about it at www.odata.org. I think OData is very exciting, and there are already other languages supporting this protocol besides .NET. To mention some; PHP and Java.
A cool thing; If a data store have a LINQ provider, it’s possible to expose the data through the OData protocol using WCF Data Services in few simple steps. If I’m not mistaken, there is a provider for db4o and a provider under development for MongoDB.

How we did it

image

To set up WCF DS over the read database, the only thing we had to do, was to create the table(s) we wanted exposed through WCF DS. Add a EDMX model to a empty ASP.NET web project, and finally add a WCF Data Service to the web project and added the entity set as a datasource (We also added some security, but when it comes to security in the OData protocol, you’re on your own. OData doesn’t say anything about how you should do this).

 image

So, to fetch data into the view model in the presentation layer, we simply use a LINQ query to get the data we want. DataServiceContext is one of the main actors in this process. The result from the query is added to the presentation model. WCF DS comes with a object-to-object mapper that makes the job mapping to the presentation model very simple. You can set it up to map all the properties in the presentation model, and throw an exception if a property is missing, or set it up to ignore missing properties.
A small code example:

DataServiceContext context = new DataServiceContext(...);
context.IgnoreMissingProperties = true;

The OData protocol gives us a lot of stuff for free; like getting the top ten records, paging, sorting, and other stuff you expect when querying a relational database. And this is just some of the abilities you get with WCF DS. Read about the conventions at http://www.odata.org/developers/protocols/uri-conventions

This has simplified the process of adding new view models to the query side and have made us more productive.

Although we only have implemented this on the query side, I see no problems using the same approach on the command side.

Tags:

Currently rated 3.3 by 12 people

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

Apr 30 2010

Slides and code from my lightningtalk at NNUG

Category: C# | Presentation | Speakerfossmo @ 02:37

Yesterday I held a presentation at NNUG about NServicebus. The code and the slide were requested by some. Here you go:

NServicebus.pdf (754.20 kb) 

NServicebusExample.zip (5.28 mb)

Tags:

Currently rated 3.0 by 5 people

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

Apr 7 2010

Renewal of MVP status

Category: Speaker | NNUGfossmo @ 03:46

About one week ago (1. April) I got a very cool email from Microsoft. I was re-rewarded as a MVP. Thank you Microsoft! The main reason for me getting this award, I guess, is my work for the community. Speaking about community; I'm going to hold a lightning talk at the next NNUG meeting in Trondheim and I'm also going to hold a lightning talk at XP2010. Hope to see you there?

Tags:

Currently rated 3.3 by 10 people

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

Mar 10 2010

CQRS made us more productive

Category: CQRSfossmo @ 17:41

The last year I have been working at a customer creating a product with a fairly complex domain model. We started of by using a DDD approach, creating a domain model, repositories, domain services, application services, thinking bounded context, using aggregates and aggregate roots. The application were based on recommendations from Evans book. Everything worked pretty well, except for one thing; we had to do a lot of mapping between the “layers” in the application. Some of it couldn’t be avoided, and luckily some of it could. One thing that bugged me was all the effort we had to go through just to show some data in the GUI.

When showing data, the data had to be dragged through all the “layers”. This felt a bit meaningless because the data didn’t have to be validated in any way, and they for sure didn’t touch any business rules on their way up.

We then started to look for other solutions, and discovered Command Query Responsibility Segregation. In CQRS the application is split into to parts; one where you only can query for data and one you only can write data. I wont go into the technical parts of how this is done in this post, but rather focus on what it have given us concerning productivity. Instead of having to focus on pulling data through n-layers just to show the data in the UI, we could put our effort into creating a more user friendly UI and and focus on important things like cranking out more functionality for the product owner. The commands in CQRS fell naturally into the ubiquitous language and it made us focused on the what the user really wants when he executes a action in the GUI.

And maybe one of the best things are that we still used the good practices from Domain Driven Design in our application. We have of course had problems, but all in all we have had more positive effects than negative.

Anyone had a similar experience?

Tags:

Currently rated 3.3 by 6 people

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

Feb 23 2010

I’m doing a presentation about CQRS

Category: CQRS | DDDfossmo @ 16:53

On Thursday, 4. march I will be holding a presentation about my experience using CQRS in a project for a customer. The meeting is held in Trondheim at the Vital building. During the meeting I will be giving away 2 licenses for CodeRush™ with Refactor!™ Pro. To participate in this event, go to www.nnug.no and register there.
Hope I will see you there

1266961907_1

Tags:

Currently rated 3.0 by 10 people

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

Feb 16 2010

The denormalizer in CQRS

Category: Administrator @ 18:06

The “denormalizer” is a component responsible for mapping data from the domain model to a denormalized table structure at the query side (an over can be found here). Usually the denormalizer component runs as a windows service at the server hosting the query side. Its only responsibility is to move data from the command side to the query side, and function as a router for messages from the write side. You might not want the same data on all the read servers.

Database tables matching view models

On the query side, all the tables match a view model in the GUI. Yes, this means you will end up with some duplicated data in the database tables, but that’s ok. Hard disk space is cheap.

Let’s look on how the denormalizer fits into the architecture.

image

When the domain model have done its stuff, an event is raised and a message is sent through a “pipeline” to the denormalizer on the query side. The “pipeline” can be a queue or something else that is fit to move the message in a safe way. I have used NServicebus with a lot of success, but there are other ESBs or other ways to do this.

Easy programming model

When the denormalizer receives the message, it spreads the data into the tables that needs to be updated . The tables have a one-to-one relationship with the view models. A GUI view can have multiple view models. What this gives you is a very easy programming model on the query side. All you have to think about concerning the denormalizer, is to insert/update the data to the correct tables. From the client, you look at the data as reporting data; meaning you can’t update or insert data on the query side.

NOSQL

All though I’m referring to a relational database at the query side in this post, it doesn’t have to be a relational database. You can use a non relational database if you want to. I would recommend MongoDB over a object database like DB4o, but that’s just my taste at the moment. You can even build your own key-value store because in most GUI views you will just fetch data based on an id.

Summary

To sum it up; the denormalizer routs the messages from the command side in to the correct tables on the query side.

Tags: ,

Currently rated 3.4 by 16 people

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

Jan 10 2010

How to set permanent path in Powershell

Category: Powershellfossmo @ 15:06

Input in powershell window:

[environment]::SetEnvironmentVariable('path',"$env:Path;c:\Program Files\Git\bin",'Machine')

Tags:

Currently rated 3.2 by 11 people

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

Jan 7 2010

Five things to think about when working with messaging solutions

Category: DDD | Patterns | Messagesfossmo @ 16:21

I’m trying to gather some of my thoughts around messages and that resulted in these 5 points:

1) A message can be created with any technology. It can be JSON, XML, Binary or a custom format. If you want to use the message in different technologies (like Java and .NET), it might be smart to go for a format supported by both technologies. Well, if you choose a technology like XML, it’s not given that you can exchange messages. XML is just a way to format your message, it doesn’t say anything about the content.

2) A message consists of two basic parts; a header and a body.
The header describes the data being transmitted and the body holds the data being transmitted.

3) The tree most important message types are (as I see it); document messages, command messages, event messages. You can read more about this messages in the book Enterprise Integration Patterns: Designing, Building, and Deploring Messaging Solutions (I’m linking to the kindle edition. I love my Kindle :-) ).

A bit more about this message types: A command message is a regular message that contains a command. It uses the command pattern to, for example, encapsulate the request and send it to another system. A document message is used to transferee a data structure between applications and a event message is used to notify another system about a change; for example a price change.

4) When working with messages, you need a way to handle them. On the .NET platform there are several open source choices; NServicebus, Rhino Servicebus, Simple Servicebus and MassTransitt (it’s probably more solutions out there). I think all of them uses MSMQ when communicating the messages, but there are other ways too. There are probably some commercial products out there too, but I haven’t tried to look them up at the moment. For the record; you don’t need a enterprise service bus handle messages. A message can be used to communicate internal in an application, for example between bounded contexts.

5) Messages are immutable. You can look at them as value objects. Greg Young puts it like this; Mutable messages are an anti-pattern. You can read more about his at Greg Youngs blog.

Tags: , ,

Currently rated 3.0 by 5 people

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