ObservableDeveloper - Leonid Sorokin's Blog

.NET, Silverlight, ASP.NET, Web Services, SQL Server, Cloud Computing, and much more...

About the author

I am a .NET Software Developer, Consultant, and Trainer from Toronto, Canada specializing in web development with Rich Internet Applications on the Microsoft development tool chain.

My Photo

Microsoft Certified Professional Developer

Architecting Silverlight 2 Applications with Prism (Composite Application Guidance)

Many people who have worked with enterprise applications over the years have realized that building maintainable applications that naturally evolve over time is quite challenging. If the application consists of many modules, it is paramount that each module be as self-contained and decoupled from other modules as possible. Otherwise, over time, the modules become more and more tightly-coupled which generally results in spaghetti code.

Prism is a codename for the Composite Application Guidance package which consists of libraries (DLLs) that you can reference in your Silverlight/WPF projects. As such, Microsoft Patterns & Practices is providing documentation, written tutorials, videos, etc., in order for software developers to get up to speed with it. You can check out the CodePlex site for Prism @ http://www.codeplex.com/CompositeWPF

Prism empowers developers to create modules that encapsulate a certain piece of functionality. Each module would be responsible for emitting a view, which would then be injected into a particular region that is present inside a containing shell. The bootstrapper is responsible for initializing the shell and enumerating the available modules in the ModuleCatalog. There is also an EventAggregator that essentially acts as a Mediator, and all event publishers and subscribers use the EventAggregator to publish and subscribe to events. As such, one module may fire an event, and a multitude of subscribers may handle that event. Therefore, the modules are truly decoupled from each other. In addition each module uses a Model-View-ViewModel (M-V-VM) architecture to separate the View from the underlying model using data binding and the Command pattern. I have previously blogged about a fully unit-tested sample application that showcases the M-V-VM pattern and the Ninject (Inversion of Control) IoC container @ http://www.leonidsorokin.com/blog/post/Architecting-Designing-Silverlight-2-Applications.aspx. By the way, Prism includes the Unity IoC (Inversion of Control) container out-of-the-box although you are free to plug-in other IoC containers in replace of Unity.

In my opinion, the real power of the Prism framework is that it uses a large number of popular design patterns, with the hope that the composite applications that you build as a developer are as maintainable and scale well over time. In most documents, design patterns are presented in isolation, but the beauty of Prism is that it amalgamates these design patterns in a form of libraries, reference implementation (Stock Trader WPF application), and written guidance documentation. You can find an excellent introductory series of screencasts that showcase Prism @ http://compositewpf.codeplex.com/Wiki/View.aspx?title=Learn%20Prism

On a side note, I have found another framework that Microsoft appears to be developing with the developer community, although so far it is only in a preview state - it called MEF (Managed Extensibility Framework). As far as I understand, this framework will ship with .NET Framework 4.0. I believe MEF is some kind of grandiose Publish/Subscribe & component discovery mechanism which by decorating properties/methods with Import/Export attributes enables a developer to basically dump a bunch of modules in a folder and have them discover other modules during run-time and not during design time, and actually use them. Also, unlike Prism, which relies of WPF, MEF has no requirement on XAML, so theoretically, it can be used with other-non WPF stacks, such as Windows Forms. MEF is still early in its development but it feels rather promising. Hopefully, MEF will be ported over to Silverlight at some point. You can check out MEF on CodePlex @ http://mef.codeplex.com


Permalink | Comments (0) | Post RSSRSS comment feed

Using the "Cumberland" .NET Mapping Framework with SQL Server 2008

As you may have heard, SQL Server 2008 now comes with two additional data types for spatial data, "Geometry" and "Geography". Thus, it is now possible to query spatial data using standard SQL syntax. You can find out more about the spatial capabilities of SQL Server 2008 @ http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx

Many people already have spatial data stored in proprietary file formats, but would like to use the power of a full-fledged database to query that data. So the question becomes, "how to we load such data into a database?"

There are two .NET Mapping Frameworks that can do this for you, and yes, there are tools that can do it for you as well, such as Morten Nielsen's shape2sql tool. You can download Morten's shape2sql application free of charge from his blog @ http://www.sharpgis.net/page/Shape2SQL.aspx

However, I prefer to use the open-source Mapping Frameworks for the simple reason that I can see the code, and alter it in case something does not work as it should.

The two .NET Mapping Frameworks I am familiar with are

SharpMap is a veteran compared to the new Cumberland framework, though I believe these frameworks complement each other. Both have data adapters that can work with spatial data in SQL Server 2008, ESRI Shapefiles, etc. In addition, Cumberland can generate Virtual Earth or Google Maps raster tiles or even KML data for Google Earth.

If you try Cumberland, please be aware that some applications may fail with a "proj.dll not found" error message. This may occur if you are running Windows Vista. This occurs because the proj.dll is actually an unmanaged DLL. It is responsible for setting projection information and you can find out more about the Proj.4 Cartographic Projection Library @ http://trac.osgeo.org/proj. It turns out that this DLL actually has a dependency on another DLL that is supposed to ship with Windows, but newer operating systems do not have it (such as Windows Vista). This special DLL is named msvcr71.dll. I recommend you download it from http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71

After you download it, just make sure both proj.dll and msvcr71.dll are in the same folder, and everything should work just fine. If you are curious how I got it to work, I highly recommend Dependency Walker which is a free tool that allows you to examine any Windows library/executable and see the dependencies it has on other libraries (whether the dependencies are on system libraries or not). Dependency Walker can be downloaded for free from http://www.dependencywalker.com

Have Fun!


Permalink | Comments (2) | Post RSSRSS comment feed