Thursday, November 26, 2009

IOC Containers – Who do they depend on?? (Part II – more NDepend)

I recently posted about IOC containers and their dependencies.  I was using NDepend in that post as an example tool to extract quick information relating to assemblies that are inherited when you add a framework to your project.

Patrick of NDepend was nice enough to point out some other features that can aid this process.  As per his blog post, you can you the build comparison tool to check two sets of assemblies. 

In this case, Unity vs Structure Map

Build Comparison

image

Output when searching for differences. (also available are searching by Method, Field, Type and Namespace)

image

As you can see, there are a number of assemblies used by Structure Map that are not used by Unity.  (Unfortunately this seems to only be a one way view, eg. I cannot seem to search for the assemblies that have been introduced.  Then again, you probably care more about the new build.). On a similar note you can also search for items that are used differently.  The output also gives an overview of the changes.  I have found this quite useful on my own builds and major open source projects updates.  (eg. Fluent NHibernate recent upgrade to consume the latest version of NHibernate)

image

As I become more familiar with NDepend, I am finding new ways to apply its tooling to improve all facets of my code base.

Get Amongst It!!!!

Monday, November 23, 2009

NHibnernate & Data Services

Just a quick note on how to expose data services (aka REST) from your NHibernate repository or any other business logic.  Say you have an entity like the one below.  Then if you mark you entity with attributes from the System.Data.Services.Client assembly you can expose the entities from a business layer that exposes IQueryable.

  1: using System;
  2: using System.Data;
  3: using System.Data.Services.Common;
  4: namespace FluentlyDo.Entities
  5: {
  6:     [DataServiceKey("Id")]
  7:     public class Person
  8:     {        
  9:         public virtual int Id { get; set; }
 10:         public virtual string FirstName { get; set; }
 11:         public virtual string Surname { get; set; }
 12:         public virtual int? Age { get; set; }
 13:     }
 14: }


Then add a Data Service that exposes your IQueryable interface property



  1: public class FluentDataService : DataService<ServiceAdapter>
  2:     {
  3:         // This method is called only once to initialize service-wide policies.
  4:         public static void InitializeService(IDataServiceConfiguration config)
  5:         {
  6:              config.SetEntitySetAccessRule("People", EntitySetRights.AllRead);            
  7:         }
  8:     }    
  9:     public class ServiceAdapter
 10:     {
 11:         private PersonRepository _personRepository;
 12:         public ServiceAdapter()
 13:         {
 14:             SessionManager manager = new SessionManager();
 15:             _personRepository = new PersonRepository(manager.CreateSessionFactory());
 16:         }
 17:         public IQueryable<Person> People
 18:         {
 19:             get
 20:             {
 21:                 return _personRepository.GetAll(); 
 22:             }
 23:         }       
 24:     }


Feed



image



There it is…



Get Amongst It!!!!

Wednesday, November 4, 2009

Locks, locks go away.

Recently we had some team members leave our project, unfortunately they still had some exclusive locks on files within Team Foundation Server (TFS).  To get around this you need to use the TF.exe tool.

The syntax is as follows. 

tf.exe LOCK "$/PathToTheFile/FileInQuestion.cs" /LOCK:NONE /WORKSPACE:WorkspaceOfTheUserWhoHasTheLock;UserWhoHasTheLock

tf.exe UNDO "$/PathToTheFile/FileInQuestion.cs" /WORKSPACE:WorkspaceOfTheUserWhoHasTheLock;UserWhoHasTheLock

Get Amongst It!!!

IOC Containers – Who do they depend on??

I am a big fan of Inversion of Control (IOC) containers.  I strongly believe when used correctly they clean up your code by at least 30% .  They also help you understand your dependencies much better.

There are many options for developers when choosing an IOC, of which most have extensive material, samples and documentation available.  Recently I was wondering what are the dependencies of an IOC container.  After all, they help apply the dependency injection pattern, but what do they in turn rely on.  To help with this exercise, I am using a tool called NDepend.  This is similar to the dependency mapping available in the Beta of VS2010 but on steroids.

I took two containers that I am familiar with.  The Microsoft Patterns and Practices implementation Unity, and the popular open source project StructureMap.

The first thing we notice about both frameworks is that they have little need to go outside the basics of the .Net framework.  As such they are both great candidates for any type of application, be it Web, WPF or services.

Unity Structure Map
DependencyGraphSnapshot image

Delving a little further, we find that both frameworks are similar in the namespaces they consume. Both making strong use of generics (to be expected), however Structure Map has some a fluent configuration options and so makes use of Linq.  It also has some specific implementations (Pipelines) that cover specific lifecycles such as ASP.Net.

Unity Structure Map
DependencyMatrixSnapshot DependencyMatrixSnapshot

Comparing components in this way gives you a better understanding of what is under the hood.  This is just a quick overview of looking at frameworks and their dependencies.  Next time that you use a framework, it might be worth considering what other components and dependencies you are inheriting.

Get Amongst It!!!!

Tuesday, October 20, 2009

Merlba Samples

Over my time as a dev, I seem to constantly need old snippets and code for quite simple tasks.  Some people use snippets, some templates however I have decided to add all mine to an open source project.

Currently hosted on Codeplex (this will be changing shortly) is http://merblasamples.codeplex.com/.  Over time I am going to use this as a bit of a dumping ground for ideas and samples that I have collated.

Case in point, I needed a simple method to allow for converting a legacy apps string representation to Title Case.  So I have added to the utilities.

public static string AsTitleCase(this string s)
{
         var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;         
         var result  = textInfo.ToLower(s);
         result = textInfo.ToTitleCase(result);

         return result;
}

Get Amongst It!!!

Monday, October 5, 2009

Telerik TFS Project Dashboard

The project I am currently on uses TFS 2008 (Team Foundation Server) and I am always on the look out for new add ins and tools to make life easier.  One I have mentioned in the past is Conchango’s Scrum Process Template.  We are also using Telerik’s suite of ASP.Net controls within the web app we are building.  These two tools now have something in common…

TFS Work Item Manager & TFS Project Dashboard

Set out as a showcase for their WPF tools, it seems to be a combination of the current dashboards  available and the Office integration.

Kanban like??

image

Who broke the build

image

It’s not quite Team City build intergration, however its could make the TFS experience all the more palatable.

Get Amongst It!!!

Friday, October 2, 2009

FIFA 10 GOALLL!!!!!

I haven't played the Xbox in a while, so to have this as my first goal was pretty cool.

Pitty it was not Timmy Cahill.

Get Amongst It!!!