Saturday, June 4, 2011

This is no Domain Service

After reading this blog entry about why and how to use the command processor pattern in your service layer. While the blog post is worth reading a code example provided by Ian made me think.

public class MyFatDomainService
{
    public void CreateMyThing(CreateMyThingCommand createMyThingCommand)
    {
        /*Stuff*/
    }

    public void UpdateMyThingForFoo(FooCommand fooHappened)
    {
       /*Other Stuff*/
    }

     public void UpdateMyThingForBar(BarCommand barHappened)
     {
        /*Other Stuff*/
     }

     /*Loads more of these*/
}

The service signature looks more than a repository, we have these CRUD methods with the "create" and "update" prefix.

Is this a domain service? I don't think so...

My suggestions is to step back and ask yourself whether you need all this "best practice"/layered architecture/DDD stuff when providing API methods like create, update and delete? Are you building the next excel like business tool creating and updating cells and rows while doing a couple of validations on the input object?

And in case you really identify a domain service give the methods some semantic names :)