Wednesday, June 23, 2010
Perth Alt.Net - RavenDb
I really do feel lucky to be in the company of some very smart people and i want to thank everyone for letting me bleat on and not give me too much grief for being woefully underprepared.
However I put it out there that the people who are comfortable enough to ask the hard questions (and there were a few), please take the reins, we want to hear from you! I’m a strong believe that you can learn as much about some from the questions they ask as the questions they answer and there were some gems last night.
Please contact Mike (@wolfbyte) or myself if you are thinking you may be interesting is starting a discussion, or even if you want to hear about stuff especially if it is edgy and possibly not suitable for the standard M$ .Net community of practice stream (Mitch wheat is the contact for that if you do have M$ specific stuff however). Any feedback is good. The hardest thing for organisers is trying to figure out what the crowd wants and as we nerds are not the most vocal people, making it even harder to run nerd events.
A further incentive is we now have sponsorship. If you get up and present you get swag, swag you want. I worked out since I have been back in Perth I have received several thousand bucks worth of cool stuff from presenting or attending various .Net events. It’s worthwhile getting involved!
Garry Stewart is up next time (in about 2 weeks) talking about light wieght IDEs, specifically VIm and letting go of our addiction that is Visual Studio.
One big note I also want to make. Take the talks for what they are. The whole under current of Alt.Net is "options". We need to be aware there are options. We are not saying you must throw away SQL and use RavenDB exclusively or Vi will replace Studio, we just want people to open their minds. If last nights talk got you thinking about how you could get you python web stck talking to cassandra, sweet, most of what we are talking about is concepts, if there is a tool involved, its just there because it facilitates a different way of thinking. Thats all.
See you next time :)
Wednesday, June 16, 2010
DDD eXchange 2010 - London
DDD EXCHANGE 2010 - PODCASTS, SLIDES AND PICTURES
Thye have recorded all the DDD eXchange 2010 talks. The slides and podcasts can be viewed here:
- Keynote: DDD Emerging Themes of 2010 (Eric Evans)
- Architectural Innovation: CQRS (Udi Dahan)
- Architectural Innovation: Eventing, Event Sourcing (Greg Young)
- The 1st Parkbench Panel Discussion
- DDD Revelations and Misunderstanding: A Report from the Trenches (Ian Cooper)
- DDD, TDD, BDD (Gojko Adzic)
- Folding Together DDD & Agile (Eric Evans)
- The 2nd Parkbench Panel Discussion
Thanks SkillsMatter!
Thursday, June 10, 2010
Test Fakes - Solving a Domain Entity Issue
Background on the design in question
- We are using NHibernate for persistence on Oracle.
- We have service that accept command that are coarse grained and perform a clearly defined business function, they are not chatty services.
- We are using the notion of aggregate roots so all child objects are created and managed by the owning aggregate root. If you need to access the child it must be done via the AR
- The domain is relatively large and complex.
Background problem
We had issues where we were dealing with domain objects in test and getting problems with interrogating child collections. For example we sometimes need to be able to update a child of an aggregate root and we were using the id of the child (within our command object) to indicate which child to update. We are using a basic database identity field (oracle sequence) for setting the ids on all of our user defined entities.
Herein lies our problem;* In our test we create an aggregate root complete with child objects. We then want to test, for example, updating a child of the aggregate root via a DTO based command (i.e. using an id to define the child to update) and we run into issues when all of the child object have the same id of 0 as they are not persisted (it’s a unit test). Now this would never happen in real life. Why would you issue a command to update something that has not been persisted, how do you even know about that object?
The quick solution that I have seen used a lot is to set the ids of all of the domain objects prior to running the test. I don’t like this if you are doing this by exposing the ID setter on the domain object. This is opening up the API of our domain for testability and is potentially the start of a slippery slope in to a pit of hell. An easy way around this is to use fakes. These object are just child object of the domain objects in question that help expose stuff the domain shouldn’t; in this case the ID setter.
The other alternative is to set the id on creation of the fake so the setter of the id is not exposed. This can also work but it will mean your fake will always have an id set. For the situation I was in this was not suitable.
The end solution
All domain objects have a fake create for it. All of the fake implement an interface ISettableId
public interface ISettableId{ bool HasIdBeenSet(); void SetId(TId id); }
With an implementation example (its id type is and integer) :
public class FooFake : Foo, ISettableId{ public FooFake(string name, TypeRequiredForValidConstruction myDependecy) : base(name, myDependecy) {} public bool HasIdBeenSet() { return _id != 0; } public void SetId(int id) { _id = id; } }
This mean we can now create fake objects and emulate persistence later by reflecting down the object graph and setting all of the ids. This is much faster than hitting the database and has proved to be a very valid exercise as we can now run tests again transient and persisted versions of the object graph without having a db connection.
One additional thing I should mention is that the creation of child object now must be exposed as a hook. For example when we create child objects I do not just new up to object and add it to a collection. I call a protected virtual method that creates the child object and then add that to the list. This allows my fake to override the return type that is added to the list so children can also be fakes. This has not increased the exposure of the domain but has now facilitate a hook to allow me to create fakes for my child collection.
Caveats:
Fakes should not include any logic. The fakes I am using only allow the setting of ids. The only logic they have is to check whether the id is set (this allows us to skip objects that have had their ids set when we walk the object graph and not go around in circles). The only other methods that are required is the overrides of the creation of child objects.
Other methods you may find in the fakes are builder methods. Instead of having big factories for creating test object you may choose to put the object creation closer to the owner by putting it in the fake class itself.
Summary
As I mentioned, we have a pretty large and complex domain we were running into issues where the difference between persisted and non persisted objects graphs was becoming problematic; using the fakes has allowed us to keep the domain clean and only as open as possible while allowing us to emulate persistence without the cost of hitting a database. Over all I’m pretty happy with the result.
*I’m sure there are other way to solve this higher level problem
Thursday, May 27, 2010
Alt.Net, Openspaces, whatever its coming...
PLEASE spread the word. We need ideas when people can come and where they would go to (Australia is a big place, we are all very spread out)
The wiki looks like its going to be based here: http://ozopenspace.pbworks.com
Register you interest here. Seriously please do this otherwise we can not estimate or cater for your needs/wants etc. This will also show sponsors if we are serious or not and may help convince overseas guest to attend too, of which there is already interest :)
The discussion is on the oz alt.net google groups here
I cant wait!
Wednesday, May 26, 2010
Powershell and the web
In my reading I have seen lots of flaky posts about PowerShell and web services. I think people need to remember that web services still conform to the http protocol, there is no magic, you do not need to access any visual studio dll or do any weird crap like that, you just need to hit the url and receive a payload.
$wc = new-object system.net.WebClient $webpage = $wc.DownloadData($url)
That's it. No weird proxies no importing custom dll's.
Here's an example calling the Google Maps API (which is a nice API BTW) to get a latitude and longitude of an address, specifically Perth's craziest bar Devilles Pad (think Satan living in a trailer park that hangs out at a Go-Go club that used to be a James Bond-villians liar, yeah its that cool:
$url = "http://maps.google.com/maps/api/geocode/xml?address=3+Aberdeen+St,+Perth,+WA+6000,+Australia&sensor=false" $wc = new-object system.net.WebClient $webpage = $wc.DownloadString($url)#Edit -Thanks Ken $xmldata = [xml]$webpage $lat = $xmldata.GeocodeResponse.result.geometry.location.lat $lng = $xmldata.GeocodeResponse.result.geometry.location.lng write-host "Latitude = $lat - Longitude = $lng"
Like that? Go play: Google Maps API Doco
Friday, May 7, 2010
MSBuild 101
MSBuild is, to be honest, very basic.
The term MSBuild is a little confusing to some as its covers a few things: a file type and an executable.
After reading that it is quite clear that MSBuild is actually very simple. It is the syntax and general XML noise that scares most people, including myself.
Running MSBuild
To start with I will show the most trivial example of how to use MSBuild and that is to just build a solution.
@C:\Windows\Microsoft.NET\Framework\v3.5\MSbuild.exe MySolution.sln
Assuming that this command is run in the directory that MySolution.sln resides this will build that solution. It can’t get much easier than that. Note this will not do anything clever, it will just build to your default location ie bin/debug for each project in the solution. Personally for me this offers little value other than it is a bit faster than building in visual studio.
Typically if I am building using the command line it is because I am building from a build tool. Build tools like PSake allow me a lot more flexibility as they are not constrained by the bounds of XML and have powerful functions I can use that may be associated to builds and deployments that might not otherwise exist in MSBuild. If you are using a tool like PSake or Rake as your build script then it is more likely that you will use the following syntax:
&$msbuild "$solution_file" /verbosity:minimal /p:Configuration="Release" /p:Platform="Any CPU" /p:OutDir="$build_directory"\\ /logger:"FileLogger,Microsoft.Build.Engine;logfile=Compile.log"
This is from a PSake script so anything with a $ in front of it is a PowerShell variable (i.e. not MSBuild syntax). Walking through this I have defined the location of the MSBuild exe ($msbuild) and the sln file. Note that the sln file is note associated to a switch. It is the first argument and this indicates that this is the file we are building. Other arguments are prefixed with a switch. These switches begin with a forward slash and end in a colon and contain either full descriptive words (e.g. /verbosity:minimal) or short hand syntax for a word (e.g. /p:Platform="Any CPU" which is short for property and in this example defines the platform property)
FYI : The & at the start of the line is a PowerShell construct to say "run this command, don’t just print it to the screen"
Defining Build Scripts with MSBuild
Let’s go over this line by significant line:
Having a build file is all very nice but we need to be able to run it. As it is not a solution of project file I tend to treat them a little different to how I would call those files directly. I typically prefer to be explicit in calling target, even though it is a DRY violation.
I have an example extracted from a bat file that calls into an MSBuild script below to show you the syntax (this is the same syntax as if you were to run from the cmd line):
From this you can see:
Stepping Up
Change a property from outside the script
Directories with spaces are failing when passing them to MSBuild
Inside your Scripts
Display a message to the console
I want to reference a whole Item group
I want a conditional execution
Error Messages
Conditional Properties
Swap out Configuration files
Creating your own MSBuild Task
Some hints to get the most out of MSBuild:
I hope that is enough to get you up and running, if not let me know and I will try to fill in any of the gaps
Tuesday, April 27, 2010
Castle - Reborn!
Of late there is a new Castle Wiki and thanks to Andy Pike a bunch of new screen cast dedicated to getting up and running with the various aspect of the Castle framework.
So the links are:
- Current site which may get replaced in the future
- New Castle wiki and general go to place
- CastleCasts
Thanks to Krzysztof Koźmic for the heads up :)
*OK so Castle is not reborn, just the doco ;)