Archive

Archive for the ‘Architecture’ Category

Service Factory Modelling Edition – part 2

July 14, 2008 Mark 4 comments

In my last post, I went over a number of issues that my project team and I had with the Service Factory Modelling Edition.

One of the issues was with respect to the generated Entity-to-DataContract translator classes, specifically the fact that the generated class contains no “collection” translation method.

Now, it may seem obvious to some that there is a straightforward way to leverage the generated methods to achieve translation of an entire collection of entities to data collection types, or vice-versa, but not everyone finds it so obvious (at least, some on my project team didn’t find it obvious!! :) )

Ok, lets imagine we have generated a translator class for an Address entity and an AddressDC data contract type. You get the following two static methods (code removed for clarity):

public static BusinessEntities.Address TranslateAddressDCToAddress(DataContracts.AddressDC from)
{
    ...
}
public static DataContracts.AddressDC TranslateAddressToAddressDC(BusinessEntities.Address from)
{
    ...
}

Now, we also have a collection of address entities (stored as a List<Address>), that we want to translate into a collection in our data contract. The data contract has been designed using the modelling tools in the Service Factory, and our AddressDC collection has been modelled as a collection of type List also.

Basically, you loop through the collection you’re translating from and for each record, you call the appropriate translator method, like so:

List<Address> output = new List<Address>();

foreach (AddressDC addressDCItem in AddressDCColl)
{
    output.Add(TranslateBetweenAddressAndAddressDC.TranslateAddressToAddressDC(addressItem));
}

Ok, so the other part of this equation is making sure that we factor this well, and don’t write this code over again everywhere we want to use it. The most logical place to put this is to write it as a new method on the existing translator class.

Of course the thing to remember with this, and this is the issue I really had with the translator generation in the Service Factory, is that the translator is not a partial class, so we have to add code to the existing code file, and because of that, we need to realise that this code will be “removed” again if the translator ever needs to be re-generated.

Obviously we’re likely to want collection translators that go both ways, so there will be two new hand-coded methods. Therefore our final translator would look something like this (again, some of the code has been removed for clarity):

public static BusinessEntities.Address TranslateAddressDCToAddress(DataContracts.AddressDC from)
{
    ...
} 
public static DataContracts.AddressDC TranslateAddressToAddressDC(BusinessEntities.Address from)
{
    ...
}
Public List<Address> TranslateAddressList(DataContracts.AddressDCColl from)
{
    List<Address> output = new List<Address>();
    foreach (AddressDC addressDCItem in from)
    {
        output.Add(TranslateBetweenAddressAndAddressDC.TranslateAddressDCToAddress(addressItem));
    }
    return output;
}
Public DataContracts.AddressDCColl TranslateAddressList(List<Address> from)
{
    DataContracts.AddressDCColl output = new DataContracts.AddressDCColl();
    foreach (Address addressItem in from)
    {
        output.Add(TranslateBetweenAddressAndAddressDC.TranslateAddressToAddressDC(addressItem));
    }
    return output;
}

Please note that this code has been coded off the cuff, and has not been tested, nor even compiled. It’s there just to give you a general idea of what to do.

Mark

Service Factory Modelling Edition – Part 1

July 4, 2008 Mark 1 comment

In my last post I mentioned that I’d be writing a bit about the experiences I’ve had recently with some of the Microsoft Patterns and Practices Software Factories. On a recent project, I made the call to introduce the use of the Service Factory Modelling Edition, the Repository Factory (a.k.a. the Data Access Guidance Package), and the Smart Client Software Factory to my team.

To get the ball rolling, I’m going to begin with a bit of a discussion on some of the issues I found with the Service Factory Modelling Edition.

This list is a pretty exhaustive list of the things that tripped us up during the course of the project. I’m not having a moan here, because overall I think it’s a pretty cool tool, and I think that the P+P group did a damn fine job of the designers in particular, considering that this is pretty much the first version of the tool to include them.

  1. The model designers don’t support cut-and-paste of sub-elements (such as primitive sub-types on a data contract). So if you have a datacontract type, that is used in two different places, you can’t copy and paste, you have to create the second one from scratch.
  2. The designers for data contract and service contract do not allow the user to manually enter the type name for types that differ from the default “System.String” – have to use the type selector GUI instead (extreme level of user interface friction). This one caused me some aggravationsince in a lot of cases, I wanted the type of a contract member to be something other than string.
  3. When using the WCF Extension, the DataContract designer should support auto-increment or auto-assignment of the “Order” property of sub-types rather than defaulting to 0 for every newly added subtype, since it is necessary to have a unique Order value for every member.
  4. There is no support for nullable types in translators. For whatever reason, the Entity to DataContract type translator codegen and wizard do not like nullable types. I had some other issues with the translators also, chiefly the facts that a) they are NOT generated as partial classes, and b) there is no ability to generate a translator for collections of a given Entity/DataContract type. I’ll cover how I got around this in a later post.
  5. No support for tidily removing generated artifacts – translators, DC’s, Services, etc. There is no easy way to undo a “generate” – you have to manually delete the generated code if you remove or rename an item using the designers.
  6. There is no out-of-the-box support for WCF bindings other than wsHttpBinding and basicHttpBinding. You need to implement an extension to provide this support. This was annoying, but was pretty easy to sort out. I’ll outline this in a later post also.
  7. There is no way to reference types from one data contract model in another data contract model. If you have a data contract type defined in a model, and you want to use that same type in more than one place, then you can only do so within the same model. This leads to some of my models being overly large, with everything on the one model or, if you do persist in splitting things up into separate models (which I think makes perfect sense), then you end up with more than one copy of the type (one on each model), which is a real problem when it comes to code generation, and keeping the two (or more!!) models in synch with each other.
  8. No support for generation of asynchronous client proxy code. At one point I wanted to be able to generate an asynchronous client proxy, but I found that this was not supported in the Service Factory Modelling Ed.
  9. The out-of-the-box service host project is implemented as an ASP.Net web site. There is no support within the service factory for self-hosting scenarios, such as hosting services in a windows service (at least, I never found any). I will also cover my solution to this in a later post.

 

Again, as I said, I’m not criticising the Service Factory. I think it really made things easier on this project in particular, as we had a very junior developer join the team mid-project (she was from the customer’s development team in fact) and I think that without this tool, she would probably still be trying to get her head around the concepts involved in service development.

Mark

Its been a while!

July 3, 2008 Mark Leave a comment

Wow, ok so it’s been a while since I’ve posted anything! Well, I’ve got some material to post on so I’m going to be doing a few more over the next few days.

I’ve recently been working on a project where I’ve been using the MS Patterns and Practices group’s Software Factories, along with VS 2005, and I have some thoughts and comments on these that I’d like to share.

Hopefully what I have to say will be helpful to someone, since much of what I’m going to post relates to solutions I found to some fairly fundamental limitations in a couple of the factories that our team used.

In particular, I’ll be addressing workarounds for issues found in the Service Factory Modelling Edition, and the Repository Factory (or Data Access Guidance Package), along with general notes on our teams experiences with these and the Smart Client Software Factory.

So, as I said, hopefully someone reading will find this interesting, or even helpful…

Cheers
Mark

Why do I hate documenting Application Architectures?

September 18, 2006 Mark 1 comment

As a general rule, I dislike writing documents – MS Word seems to be able to put me to sleep every time. But when it comes to Application Architecture documents, it’s even worse than usual.

Why? I’m pretty sure that it’s got to do with generalisation – I love thinking about application architectures, and I love building them, but when it comes to writing about them, the fact that everything needs to be so general really puts me to sleep.

To think about an architecture I like to look right through it, and try to come up with a picture of a complete implementation of it. The problem with documenting the architecture I think stems from the fact that I have to “switch off” the part of my brain that automatically looks for a concrete example in order to validate the architecture I’m writing about. By forcing myself not to think about that part of it, I can concentrate on documenting the architecture itself. But that leaves a large percentage of brainpower that is now doing nothing. The only other time I’m not thinking about 5 different things at once is when I am sleeping, so my brain tries to make me fall asleep.

So if my boss is reading this - THAT’S why I was snoring this afternoon!!! :)

Categories: Architecture