Service Factory @ Application Designer

I planned this for Visual Studio 2008 Beta 2, but the Service Factory isn’t available for Beta 2, yet. So, this implementation is still on VS2005. Should be no problem to change it in the future.

Anyway, as I mention in a previous post, Team Architect lets you focus on the system design and the connections between them. With a Top-Down-Design approach you can model your system [system of systems / applicationlandscape] and fine-tune the details during the design without technology details.

In the current versions of Team Architect [VS2005 and VS2008] the lowest model in the Top-Down-Design is the Application Diagram not that low and not low enough for code generation [although I made some extensions to the Application Diagram which made this possible and by default you can implement them with a template]. The Service Factory can fill this gap for the endpoints [service providers].

So, I attached the Service Factory to the "Implement application" feature of the Application Diagram, let a "GatheringService" collects all the information and generate the service models from it. After this developers/ “service modelers” can add extra information to the servicemodel, for example technology specific properties and information / business analysts can add datacontracts to the data model. From there we can generate the code.

A small walkthrough [see image]:

  1. Design the system [see this walkthrough].
  2. Model the application diagram and set some additional information.
  3. Add detailed information about the endpoints in the "WebService Detail" window.
  4. With the method "Implement Application" generates the service model.
    In this model you can set more detailed information about the service.
  5. Let Information Analysts or import XSD's for the Datacontract Model.
    This information isn’t available in the Application Diagram only the naming of the contracts. That’s fine, because I think datacontracts are business information and shouldn’t be modeled in an Application Diagram.
  6. Generate code from the Service Factory.
    This will conform to the current available Best Practices and implentes Design Patterns!
  7. The last step hasn’t any thing to do with code generation but with visualization.
    When I made my first code generation from the Application Diagram, I got allot of comment about the "Box" that has allot of intelligence. So, when I'm able to show people a little more details they are more comfortable it.

modeling

Some things to think about.
At first sight it looks great, but there are some challenges to take and some decisions to make.

First Roundtripping. Team Architect has got roundtripping and by using a custom template you lose this functionality, this is not a problem because I don't want roundtripping. And this will bring use by the discision: The highest model is the master. So, the application diagram is the master of the service model and this one is the master of the code.

Second Regeneration of models and code. Because we don't have / want roudntripping and the upper level model is the master, we got the question "what about changes?". For example I change the namespace in the Application Diagram after the service model is generated. What will happen with this model? For sure you don't want to generate it from scratch and lose all the settings that are made in the service model or code.

Third Executing from outside.  Because I want the models to be in sync I want to run the code/model generation from time to time. For example you can regenerate everything on the Save event or you can run them during a build. Anyway, I don't think this is possible in VS2008 just because the AD hasn’t got any extension point to this. So, this is going to be a custom action.

Probably more challenges to come ;-)
Some nice thinking about models can be found in this post from Harry Pierson.

How To Customize the "Service Factory Modeling Edition" to work with Visual Studio Team Architect.
I already had made a class structure which collects and holds the information from the application diagram. So I can easily iterate through the applications, endpoints, details and other infromation. The P&P team also made a small extensibility walkthough "Importing Model Elements from an Arbitrary File Format", which made things much easier.

Going for the quickwins, I started with the generation part. Add a custom recipe "ImportADAction" and let the Execute method collects the data from the AD file, iterate the object model and generate the service model. See the P&P walkthrough for the details.

Next step, attach the "ServicesGuidancePackage.vstemplate" template to the application diagram, this can be done in the properties window of a Application Diagram Shape. When you run the "implement application" methode the template wil launch the Guidance Package "CreateSolution" recipe.

During the execution of this recipe a wizard will ask for the modelname. For sure I don't want a dialog to appear during this step. So, I need to change this recipe and collect the model name from the AD... it should be the same name as the shape I clicked.
tmpleWhen you use the IWizard interface a dictionary "replacementsDictionary" is used during the RunStarted() method. The Unfold method of the GAX also uses this. See image. I'm still not able to get the values I want [any help on that would be great]. Meanwhile I'm working with hardcode strings. So I can work on.

Create the service model project. Because Argument Values are collected before the actions execute and the model project is created in the same recipe as where the service model/diagram is created we can't use ValueProviders. We have to collect the data [ModelProject, Store, ...] in the Actions. This was a bit challenging [also because I'm not an expert in DSL's] but after some trial and error [allot of errors] and the DSL book, I managed to create a service contract from scratch by using the "Implement Application" feature.

The first initial steps to create a service contract from the application diagram succeeded. Next is the regenerate functionality... I will post about this later on.
Mean while this post from Jezz Santos and this from Edward Bakker are great for further reading about this.

This is how it looks...

result

Still alot of work to do, but it's a nice start.

Comments (2) -

Clemens,

I really liked your posting. I think it's a shame that Modeling Edition and Service Factory do not play nicely together. I tried to follow your steps above for customizing my version but was quite unsuccessful. Is there a template, MSI or, perhaps, more detailed instructions that you could post or send me?

Thanks,

Michael

Hi Clemens

I enjoy reading your articles.
I hope you (or somebody else who you know) can give me advice how to achive what I am going to explain bellow.

I very much like idea of integration Software factories and VS 2008 architect edition.

I believe you heard about Codesmith Nettiers and Dotnetnuke Open source CMS project.
Nettiers currently produces a lot of code that is currently not relating to Dotnetnuke (it doesn't use base classes or interfaces from Dotnetnuke nor Data Providers from Dotnetnuke)
I would like to marry Nettiers way of generating DAL, BL and ASP.NET Admin template pages and Dotnetnuke.
I would prefer a Dotnetnuke developer have a Web software factory for creating a new module that would allow him to create many asp.net ascx controls from DB. I would like to have a DSL designer that would help them in configuring GUI, Business layer and DAL interaction.
If I understand it correctly DSL designer and the properties of elements placed on it will define parameters for code generation. Nettiers only has Codesmith templates and property pages for accepting input.
I would also like to incorporate LINQ to SQL or LINK to Entity. I would like to have a Guidance navigator and Recipes for various tasks. I would also like to have code regeneration of multiple files from a DSL instance without affecting existing code.

Any similar attempt being done where a DSL designer was used to facilitate code GUI re/generation +BL and DAL from DB?

How would I incorporate .NET 3.5 features to avoid creating a base class and have code regeneration not affecting existing code.
Something similar to:   “Avoiding a Base Page In ASP.Net” dotnet.org.za/.../...g-a-base-page-in-asp-net.aspx



Thank you in advance,
Rad

Add comment