mcnerlin.com

Enterprise Library 5.0 Released

by Andrew McNerlin 26. April 2010 22:38

The Patterns & Practices team at Microsoft have just released version 5 of their Enterprise Library  which is definitely worth a look.  I’ve been using parts of the Enterprise Library for quite a while now but must confess that I haven’t had cause to use all the application blocks.  There was a time that I made extensive use of Data Access Application Block (DAAB), which was released even before the first version of Enterprise Library, but with the emergence of new .NET ORMs and alternative data access strategies I’ve drifted away from it.  Unity was a welcome addition in Enterprise Library 4.0 and its good to see that this latest version of the Enterprise Library now internally uses and supports the Dependence Injection pattern

Overview of the Enterprise Library
Enterprise Library is made up of a collection of ‘Application Blocks’ which are effectively software libraries to support best practice and code reuse within common areas of application development.  Version 5.0 does not add any new Application Blocks, but instead concentrates on improving what was there in v 4.1.  The available application blocks are:

  • Caching Application Block
  • Cryptography Application Block
  • Data Access Application Block
  • Exception Handling Application Block
  • Logging Application Block
  • Policy Injection Application Block
  • Security Application Block
  • Unity Application Block
  • Validation Application Block

Its also worth noting that all the blocks are designed to be extensible, not only by using provider model style extensibility, but full source code is available from CodePlex.  Even if you decide not to use any of the application blocks there is a lot to be learned from the source code.  After all this is intended to be best practice guidance.

What’s new in v 5.0?
As mentioned above there are no new Application Blocks in this release, but instead they have concentrated on improving what’s already there in terms of both the architecture and functionality of the existing Application Blocks.  The key improvements are:

  • Support for .NET 4.0 and Visual Studio 2010
  • Improvements to the architecture including full support for Dependency Injection (DI)
  • Independence from Unity should you want to use an alternative Inversion of Control (IoC) container e.g. Windsor
  • Improvements for configuration (config wizard, Intellisense XSD Schema + more)
  • DAAB supports asynchronous data access, unit testing (via DI), has LINQ support and supports data>object mapping
  • Performance improvements

There are a few breaking changes between 4.1 and 5, but the one that will affect most people is the merge of ObjectBuilder2 into the Unity assembly. 

Why use Enterprise Library?
Its worth pointing out that there are a number of good alternatives to these application blocks out there which are freely downloadable and have good community support.  I’m not going to try to convince anyone that these are the only option or even the best option when it comes to selecting a framework, but it is certainly one that you should consider.  Here are some plus points for selecting the Enterprise Library:

  • It is a suite of blocks from a single provider, therefore it has a consistent style and is well integrated with other components in the suite.  Developers may encounter a shallower learning curve when learning subsequent Application Blocks.
  • It comes from Microsoft, so it will be much easier to get buy in from managers in some organisations.  Its not always easy to convince the powers that be to use an open source, community based framework, especially if you are writing business critical software. 
  • Good samples, support and lifetime.

Notable alternatives
Its worth mentioning some of the alternatives to these application blocks.  These include:

Caching Application Block
Although this block is widely used and works well I'm not sure how much of a future the Caching Application block will have, especially with the release of AppFabric.  Its also worth looking at memcached.

Logging Application Block
The logging in Enterprise Library is pretty good, but you may also want to look at log4Net (which is a very popular port of log4j) or nLog.

Data Access Application Block
There is a myriad of options out there for data access so I'm not going to try and list the alternatives, but suffice to say there are plenty of them.  Its worth considering the performance characteristics of the option that you choose, remembering that some data access strategies will generate dynamic (and sometimes poorly performing) SQL.  DAAB works nicely with sprocs.

Unity Application Block
Unity is a lightweight Inversion of Control (IoC) container which is used throughout the Enterprise Library.  Alternatives include Spring.NET's IoC Container or Windsor.


Shout it

Tags: , ,

Development | Architecture

Visual Studio 2010 UML + Modelling

by Andrew McNerlin 9. April 2010 14:11

I’ve been playing with the modelling features in VS 2010 to see what its capable of and I like what I’ve seen so far. 

Dev10 adds a new project template called “Modelling Project” in which you can create a series of new diagrams.  These diagrams include 5 of the 13 UML 2.x diagrams plus a Layer diagram and a Directed Graph diagram (.dgml).

Modelling Project - Add new item

UML Class Diagram
This works very well and seems to be an excellent tool for creating your logical model.  At first you may think that this would replace the class diagram that was introduced with VS 2008, but there are some key differences.  The existing class diagram (.cd) is a ‘live’ visualisation of your code.  You can reverse engineer it from existing code or create code stubs from the diagram.  The new UML Class Diagram (.classdiagram) has no links to your code at all, there is no reverse engineering and if you want to do code generation you will need to use T4 text templates.  From what I’ve read reverse engineering is a feature that is being worked on so we will see it at some point.

UML Sequence Diagram
This is the only diagram type that does support reverse engineering and I’m very impressed with it.  By right clicking on a method in your code you can select ‘Generate Sequence Diagram’ and get something like this:

UML Sequence Diagram

You can navigate from the diagram to the code with a simple right click ‘Go to definition’. 

UML Use Case Diagram
This is pretty much what you would expect for use cases – a simple drawing surface to aid the modelling of use cases.  Useful and I’m glad its now a part of the VS IDE.

UML Activity Diagram
Again this is pretty much what you would expect – an activity diagram drawing surface and simple to use toolbox for adding items to it.

image

UML Component Diagram
As with the Use Case and Activity diagrams this is a drawing surface for constructing component diagrams.  Not much else to say here: simple and better than Visio.

Layer Diagram
This diagram is intended to represent the layers of your architecture and it slightly more than just a drawing surface as it has a Layer Validation feature.  By assigning code to different layers in this diagram (a drag and drop exercise) you can generate and validate the dependencies between the classes to ensure that there are no incorrect layer dependencies.  I know I would have found this useful in the past when developers have incorrectly added dependencies which violated the architecture.

The Patterns and Practices team have also created a set of guide layer diagrams which you can add on with a small download.  This will give you toolbox items for the following reference architectures:

  • Web Application
  • Rich Client Application
  • Rich Internet Application
  • Services Application
  • Mobile Application

image

Directed Graph Document
Directed Graph Documents (.dgml) are used for a number of different features in VS 2010 (e.g. Dependency Graphs).  It is a generic document type to represent any type of node/connection relationship. Below is a simple Namespace dependency graph

image

The modelling is definitely a step in the right direction and what I’ve seen has been impressive , but I cant help but feel that there some features fell below the line when it came to the release of Dev10, specifically in relation to the UML Class diagrams.  That aside I’m pleased that I’ll be able to do a lot of my modelling in VS from now on.

** Update 16/07/2010 - The UML and modelling features have been enhanced by the release of "Visual Studio 2010 Visualization and Modelling Feature Pack" - read more about it here. **

Shout it

Tags: , ,

Architecture | Visual Studio

SVG support in Internet Explorer 9

by Andrew McNerlin 9. April 2010 00:12

Microsoft has recently announced that the upcoming release of Internet Explorer is going to have native support for  Scalar Vector Graphics (SVG).  IE is the last major browser to include support for SVG with Opera, Firefox, Safari and Chrome (+others) all already having this feature.

SVG support on IE has been possible by using various browser plug-ins,  but the story has been patchy.  Initially Adobe SVG Viewer was the best choice but when Adobe bought Macromedia in 2005 it announced that it would discontinue support for the SVG viewer (presumably as SVG was seen as a competitor to Flash).  Since then RENESIS Player has been the best alternative, but with no native IE support and Adobe discontinuing support some felt that SVG was a dying standard.

This announcement is excellent news for the SVG community and having worked on an SVG mapping application in the past I’m glad that this is finally happening.

If you’re developing SVG applications you may also be interested in this Visual Studio Extension which gives you intellisense for SVG.

More info
Channel 9 Live at MIX10: SVG Web Panel
IEBlog – SVG in IE9 Roadmap
Platform Preview gives Web developers first taste of IE9

Tags: ,

Development

Why choose a UI design pattern? (Part 2 - MVP)

by Andrew McNerlin 7. April 2010 15:49

In the second part of this blog posting (part 1 here) I’m going to examine the Model View Presenter (MVP) pattern.  We’ll take a look at how the pattern can work, the pros/cons and an example of implementation.  Please note that this is one example of how to implement the MVP pattern and this is not the only way you can do it.   I am a big fan of this pattern and in a lot of cases this is my preferred way to develop UI’s.

The pattern is separated into 3 elements:

View
The actual user interface that displays data and receives commands from the user.  This could be an ASP.NET WebForm, a WinForm, WPF page etc.  The commands are handled by the view, but it passes the command to the presenter which contains the logic.  This way multiple views can share the same presenter logic.  The only time I put UI logic in the View is when that logic is specific only to that view (e.g. I would not put ASP.NET specific logic in the presenter – I would keep it in the UI).

Presenter
Marshalls data between the View and the Model and vice versa.  Receives commands from the view and performs UI logic e.g. validates and persists model data when a button is clicked.

Model
The domain model representing the data of a particular system.  In my example this is in the Business Layer (BL).

Pros

  • Facilitates automated unit testing
  • Allows multiple UIs to share the same presenter logic (DRY)
  • Improves separation of concerns in UI code
  • Can be implemented in most UI scenarios (WebForms, WinForms, WPF)

Cons

  • Takes longer to design and implement than a traditional ‘Forms and Controls’ UI.
  • Some thought required as to how much UI logic resides in the view and how much is in the presenter.  It is more correct to have the logic in the presenter, but in some scenarios it will be more practical and pragmatic to have it in the view.
  • Tight coupling between the View and the Presenter (unlike MVVM)

Sample code
I have put together some sample code which demonstrates this pattern.  The code shows how to implement multiple UIs from the same presenter – in this case a WinForms, WebForms and WPF UI.  It also shows how to write unit tests against the presenter – in effect giving you a testable UI.  Alternatively you could use one of the .NET MVP frameworks out there

Download the code as a VS 2008 solution.

Related information
Martin Fowler has proposed two variants of this pattern (Supervising Controller and Passive view)
MVC# – a .NET MVP framework
An excellent Code Project article describing how to implement the MVP pattern.

Any comments or feedback is welcome.

Shout it  

Tags: , , ,

Design patterns

About

Andrew is a Software Architect based in Antrim, Northern Ireland, but currently contracting in London Andrew McNerlin

Advertisement