In the first part of this article I showed how I’ve been testing code using MEF and a generic base class that is in charge of wiring up the dependencies.
In this part I will focus on how I got WCF to wire up my web service using MEF in what I think is quite an elegant way.
My first requirement was to be able to write a web service that will use dependencies (imports) but that wouldn’t require me to write the composition code in the service class itself. Most of the examples I saw online didn’t provide me with a good way to do that unfortunately.
Until I came across this excellent post by Tim Roberts which shows how to tap into the WCF pipe-line and have your services composed automatically instead of having to do it per service or including wire-up code in your classes.
While the code Tim provided was a great start I thought it wasn’t just right for me. Specifically it was the fact that it required custom code in the Global.asax file which for me was not as elegant as it should be.
So I’ve done a bit more digging into the WCF pipe-line and discovered that I could achieve an elegant, completely configuration-based solution by implementing my own endpoint behavior.
In the end I needed to only create 3 classes to achieve this: EndpointComposedElement, ComposedEndpointBehavior and ComposedInstanceProvider.
Continue reading “Unit Testing, WCF and MEF – Part 2”
This article will focus on how I’ve adopted unit testing in .NET using MEF and how to also apply this to WCF web services.
I haven’t been dedicated to unit testing for a long time but once I started I couldn’t stop. There are many great benefits to doing unit tests, I wont list them here but a good article to read is at: Agitar.com
What made me build something on my own? I wanted something light that I could also integrate into existing code without making too many changes. So I focused on a couple of things: Testing and Dependency Injection. I wanted an elegant solution that didn’t rely on external libraries or that will require a steep learning-curve.
In this article I will focus on these topics and how I solved it for myself. I’m not going to dive into other topics such as The SOLID principals, TDD, Dependency Injection, Mocking, etc. If these terms are not familiar to you, I suggest you read up on them first.
I’m actually going to divide this article into two parts, to keep them shorter and to the point:
Continue reading “Unit Testing, WCF and MEF”
With SDL Tridion (R)5.3 and the introduction of Modular/Compound Templates, the way of doing templates as radically changed, no longer we had to use an old and obsolete technology such as VBScript. We could finally use .NET and Visual Studio to write template code as well as introduce “new” technologies such as XSLT with the help of Mediators (see XSLT Mediator).
One of the biggest advantages of this change is the ability to reuse existing code in a structured and clear way. Logic can be placed in dedicated classes, OO concepts can be leveraged for inheritance, encapsulation and more.
This led to the TemplateBase class which I and many others have been using for several years now. Around it I have also grouped additional classes to support reuse of common functionality that can be carried from one implementation project to another. This is known as the Templating Base Project.
If you’re unfamiliar with the Templatebase class and the Templating Base Project I suggest you hurry and get yourself over to SDLTridionWorld.com and download the code now – Template Base Project
Continue reading “Calling all Tridion Developers”
Lately I’ve worked on a Gravatar library for .NET which I released in July. I have also recently had the chance to work on Tridion GUI extensions for a customer.
This got me thinking; wouldn’t it be cool to integrate the two? Almost immediately I thought; yes, it will be cool!
So I’ve set to work on a nice GUI extension that will bring Gravatar to Tridion users and give the GUI a bit of a social touch make it feel more personalized by displaying a personalized photo for each user.
And so the integration is really 3 different extensions that can be each used individually or together.
Current User Photo
The first integration shows the Gravatar photo for the current user logged on to the Content Manager Explorer:
Continue reading “Integrating Tridion with Gravatar”
A couple of weeks ago I announced the release of the first .NET implementation of the Gravatar API.
Gravatar.NET is available for download on Codeplex.
What I’d like to show in this article is how to make use of the library using jQuery and WCF to create your own Gravatar client (Ponderi.com style).
This article will demonstrate how to show a user their Gravatar account images, allow the user to activate a different image or delete it.
I will build upon many of the concepts I described in an earlier article I wrote called: “Creating a Webservice Proxy with jQuery”. So if you like, check it out first as I won’t go into the basics in this article.
Continue reading “Creating a Gravatar client with jQuery and WCF”
For a while now I’ve been working on an implementation of the Gravatar public API.
Unfortunately it took longer than I had intended, what with those pesky work commitments and personal life issues…
I’m glad to tell you that Gravatar.NET is now available for download on Codeplex.
If you don’t know what Gravatar is, it’s: “A Globally Recognized Avatar”, allowing you to store a personal image (or images) and reuse it across different websites that support the use of it (example: WordPress.com).
If you’re building a website that includes storing user account information, and let’s face it, what website doesn’t do that these days, then typically one of the things your users expect is to be able to associate a photo to recognize their account on the site. Instead of having to store and manage these photos on your server (sometimes with a bandwidth/storage limit), Gravatar can do it for you.
Continue reading “Announcing Gravatar.NET”
Updated (25/06/2010): Fixed typos in code example
Updated (16/11/2012): Fixed missing comma.
I have been working on a website recently and one of the pages on the site has a main functionality of showing dynamic results returned from a AJAX
call to a WCF service.
As I was developing and continuously testing with Firefox I was happy to see that my code was working well; based on the URL the results on the page will differ as expected.
However, When it came to test the page with Internet Explorer the results were dramatically different… No matter what the URL was the same content from my initial request kept appearing on the screen! Quickly enough I realized that it wasn’t something wrong with my code but with IE, after all in Firefox and Chrome it was working just fine.
So naturally, I googled for a solution and found this StackOverflow thread that confirmed to me that this was indeed an issue with IE. Unfortunately, the good answers there were only helpful to those who use jQuery to initiate the AJAX requests but I was using the proxy generated automatically by ASP.NET, so I had to find my own solution as I was unable to find anything useful online.
Below are ways you can use to fix the problem. First, I’ll show how to fix it when using the MS Service Proxy and then how to fix it when using jQuery.
Continue reading “IE Caching Ajax Results – How to fix”
Its Friday evening, a good time to share a little something I’ve been working on.
.NET 3.0 brought with it a fantastic new language (VB, C#) extension called LINQ which stands for Language-Integrated Query.
Microsoft describes it as “a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.”
In short it gives the developer a more general syntax for querying sets or collections of data.
The beautiful thing about LINQ is that it can be used over any collection whether its XML, Database or even objects so long as they support the IEnumerable<T> interface.
For more information see the resources section of this article or simply google/bing it.
Continue reading “LINQ to Tridion”
Quite a while ago I internally blogged about creating a custom Sitemap provider in ASP.NET. Even though its been a while I believe its still relevant, especially the SQL caching example I added. Hopefully you can still get something out of it.
With ASP.NET 2: Microsoft introduced a few services which are built on top of the provider model.
Services such as the membership or sitemap rely on providers to supply them with the actual information. All the providers are derived from the ProviderBase class.
The default Sitemap provider is the XmlSiteMapProvider which is used by ASP.NET to retrieve the website’s navigation structure stored in the Web.sitemap file.
The cool thing about this is that we can easily extend these providers if we need different functionality than what Microsoft provides. So As long as we keep inline with the providers’ interfaces the services will work with our own customizations just fine.
A benefit of creating a sitemap provider that reads from a database should be obvious: Its pretty easy to add custom navigation where needed to new or existing sites by reading ready information from our application data store. The information in many cases will already be structured in a hierarchy so its easier to retrieve it for a navigation structure. This allows us to create the main site’s navigation, breadcrumbs, or specific structures for different sections of our site in a pretty easy way to implement, no need to write additional files on to the webserver’s file-system and the caching mechanism shown in this article gives a boost for performance.
Continue reading “ASP.NET Custom Sitemap Provider”
Here are a few useful extension methods I’ve created recently for working with Tridion’s TOM API. Continue reading A Few Useful Tridion Extension Methods