Umbraco 5th birthday meetup in Sydney @ TheFARM

Come on down to TheFARM to share in some beers and take part in the global Umbraco 5th birthday festivities.

Your hosts will be core Umbraco team developers Shannon Deminick & Aaron Powell, both of whom work for TheFARM (http://www.thefarmdigital.com.au).

The plan is for Shan and Aaron to run a Q&A session with some demo’s of the fun stuff TheFARM has been doing with Umbraco 4.1 and the work they have been doing on this next release.

  • They'll have a look at all of the new features/fixes for 4.1 (are there are TONS)
  • They'll go into a bit more in detail on some of the new things that we've integrated into the core such as LINQ to Umbraco, Umbraco Examine, new controls, enhancements, preview, etc…
  • They’ll show you some of the sites we’ve built and talk through some of the implementation’s with things like Flash

Hopefully, with two of the core team on hand we should be able to answer most questions thrown at us – give us a go!

Once we're out of beers... TO THE PUB!

All of the details, address, etc.. is on the Our Umbraco website. Have a look and RSVP now!

http://our.umbraco.org/events/umbraco-5th-birthday-meetup-in-sydney

 

Just in case you don’t want to click through here’s the event details:

Tuesday, February 16, 2010 - 6:00 PM
Suite 101, 4 - 14 Buckingham st Surry Hills, NSW

Posted on 2/12/2010 6:46:45 PM by Shannon Deminick

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: Technology | The Farm

Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Nexus One vs iPhone = Google vs Apple?

Google’s answer to the iPhone – the Nexus One smartphone – may be yet to hit Australian shores but it’s already got Farmers' chins wagging.

The topic – not so much the merits of one phone vs the the other – though you can read about this here http://bits.blogs.nytimes.com/2010/01/15/torn-between-two-phones-nexus-one-vs-iphone/?ref=technology – but what the competition bodes for the future of the www.

While the smartphones might work well with their own software they don’t seem to be making an effort to get along with one anothers other services. Some commentators – namely Tim O’Reily - think this bodes a bloody period of competition that could threaten the interoperable web of today. In the 80s it was Macintosh v Microsoft – in the 2010s the war looks set to take place between Apple and Google.

O’Reily may be onto something. While it’s too soon to tell if the Nexus One will emerge as a serious competitor to the iPhone, some Farmers have already taken sides.

Those who like that Google’s Android platform is more open to developers champion the Nexus One. The others, like everyone else, are so deep in iPhone love they can’t see past their touchscreens. One Farmer has even suggested we change the phrase “the best thing since sliced bread” to “the best thing since the iPhone”.

What do you think? Will you trade in your iPhone for a Nexus One? And who’s your money behind in the war for the web?

Posted on 1/20/2010 10:22:00 AM by EmmaSheehan

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: Hot Press | iPhone | Technology

Tags: , , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

New Facebook Ad targeting & the future

I came accross some future predictions around Facebook penetration a couple of days ago and is it truly staggering.

Discounting China (Facebook is restricted there) it looks like we will  be approaching 30% of the worlds active internet population will be regular Facebook users by the end of 2009.

In the article they also talked about future projections and the possibility the Facebook audience could possibly top 1 billion users, the digital universe would sure be a different place, for a start we have to play by Facebook's rules while on their platform.

As agencies and marketers what does this mean for us? Well I guess it certainly means no matter who you are at the moment you cannot ignore the big F. The most obvious way to tap in to this huge potential audience is through ads but until now they have been targeted in a fairly standard way. These ads have been more effective in my experience than standard units due to organic impressions generated, context and their non banner like appearance but the targeting has been at best unimaginative, certainly not taking advantage of the social platform.

There is a new option open to us though which seems subtle at first, you can simply target your ads at friends of your connections. These connections are defined by Facebook as: Fans of your page, users of your applications, members of your groups or attendees of your events. Looking in to it a little further this is a different method than the top ten targeting methods currently available. 

Why? Well the ads can have social context which is after all what Facebook is supposed to be about. So if I am working on a new film theatrical release and someone fans my new movie page I can target ads at their friends which will list below the ad that their friend is a fan of my film. If the person viewing the ad would also like to see the film and I am offering pre-release tickets or a competition, who are they going to ask to go with them I wonder.

It is a great step in the right direction I believe for Facebook, there is still much work to be done, I could rattle on for hours about the numerous ways I would like to use the platform but lets save that for another day and simply be happy they are thinking about us little agencies and marketers.

Posted on 11/13/2009 10:29:00 AM by PhillipMcCann

Permalink | Comments (13) | Post RSSRSS comment feed |

Categories: Hot Press | Technology | Marketing | Social Media

Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

WiggleTime! rewarded in the KidSpot Best of Awards!

[2009] The FARM is very proud to announce that WiggleTime! has received a Highly Recommended mention in the 2009 Kidspot Best of Awards! We are very pleased to be recognised in the realm of children's education and online learning. A testament to the heights achieved by the FARM's design and development teams. Let's get Wiggling!

Posted on 11/12/2009 11:56:00 AM by KristinaReddaway

Permalink | Comments (1) | Post RSSRSS comment feed |

Categories: Creativity | Project Releases | Technology | The Farm

Tags: , , , , , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Attic Living

 

[July 2009] TheFARM launches a site rebuild for Attic Living incorporating brand new design, additional functionality and a clear call to action. Through the rebuild TheFARM contributed to encompassing the business' 3 core services under their strong brand identity, creating a solid 'one-stop-shop' for Attic storage and conversion needs.

Built using the Pegboard CMS the site is compromised of components (or modules) including the introduction of the e-commerce facility. Allowing users to buy products online coupled with demonstration videos enhanced the DIY character of the company. Alternatively the clear call to action to Book a Consultation online reinforces Attic Living's position as leading experts in the field. 

Posted on 7/27/2009 3:40:00 PM by KristinaReddaway

Permalink | Comments (30) | Post RSSRSS comment feed |

Categories: Project Releases | Technology

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

The FARM adds a nail to the coffin of IE 6

Days until TheFARM drops support for IE6



We are happy to announce that we will cease to support IE 6 development from Oct 31 2009. We will continue to support our clients’ existing websites but any new development will target Firefox 2+, IE 7+, and Web kit browsers (e.g. Safari, Chrome).

IE 6 was released in Aug 2001, it is 8 years old and 2 more browsers have since been released from Microsoft… it’s about time people stop using this horrible, horrible browser. Other larger players including YouTube have also stated that support for IE 6 will stop. We’re hoping that more agencies will adopt this idea and push for clients to finally make the upgrade or switch to a new browser… it’s 8 years old!

Comments are always welcome!

Posted on 7/20/2009 6:01:00 PM by Shannon Deminick

Permalink | Comments (126) | Post RSSRSS comment feed |

Categories: Technology | The Farm

Tags: , , ,

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Super easy jQuery events

I've been using jQuery for a while but haven't really been using it much in the form of building custom classes or libraries. I've been working on re-developing Umbraco's JavaScript tree using jsTree (which is great by the way!) and have been writing a JavaScript library to support it. As with most code libraries, events play an important role in writing clean and effective code. In the past I've always used simple callback methods for "event handling" in JavaScript, but this isn't really an event system since it doesn't allow more than one subscriber. After some quick research, jQuery has this all built into the core, and by adding a couple very simple methods to your JavaScript classes, they will instantly support an event model!

Quick example: 

var myObject = { 
  addEventHandler: function(fnName, fn) {
    $(this).bind(fnName, fn);
  },
  removeEventHandler: function(fnName, fn) {
    $(this).unbind(fnName, fn);
  },
  doSomething: function() {
    $.event.trigger("somethingHappening", [this, "myEventArgs"]);
  }
}

The above example is an object defining 2 functions to manage it's event model and another method which raises an event called "somethingHappened" with an array of arguments that will get bubbled to the event handlers.

To subscribe to the events is easy:

function onSomethingHappening(EV, args) {
  alert("something happened!");
  alert("sender: " + args[0]);
  alert("e: " + args[1]);
}
//subscribe to the event:
myObject.addEventHandler("somethingHappening", onSomethingHappening);

You'll notice that the above event handler function has 2 arguments, one called "EV" and one called "args". The EV parameters is the jQuery event object and the second one is the custom arguments object that was created when raising the event.

Since Umbraco's admin section uses an iframe approach, i though that managing events between the iframes would be an issue since they are all using seperate jQuery instantiations, but by raising and consuming events with the above method, this is no problem.


Posted on 3/26/2009 12:08:00 AM by Shannon Deminick

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: Technology

Tags: , ,

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Selection Problem with Custom Media Type Content in Umbraco 4

The Problem

You have a custom media type. You want to add a link to it in the WYSIWYG editor. 

You go to add a link as normal, except in the "Insert/Edit Link" pop up, you click on the "Media" tab. You notice that when you click on it, no url is inserted in the Url field. 

 

The problem is due to this method in the Umbraco source:

        private static string findMediaLink(Media dd, string nodeLink)
        {
            Guid uploadGuid = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
            foreach (Property p in dd.getProperties)
            {
                if (p.PropertyType.DataTypeDefinition.DataType.Id == uploadGuid && !String.IsNullOrEmpty(p.Value.ToString()))
                {
                    return p.Value.ToString();
                }
            }
            return "";
        }

 

This method is called from the overrided Render(ref XmlTree tree) method in Umbraco's loadMedia class. Here is the code block:

        string nodeLink = findMediaLink(dd, dd.Id.ToString());
        if (!String.IsNullOrEmpty(nodeLink))
        {
            xNode.Action = "javascript:openMedia('" + nodeLink + "');";
        }
        else
        {
            xNode.Action = null;
            xNode.DimNode();
         }

 

Notice that when findMediaLink() is called, your custom media type is never going to return  "5032a6e6-69e3-491d-bb28-cd31cd11086c" as a Guid. So your media type never gets assiged it's openMedia action, and xNode.DimNode() will always be called.

 

The Work Around

You must replace the Umbraco media tree handler with your own one. We called ours "MediaTree".

Here's how:

  • Create a class (eg. MediaTree) that inherits from loadMedia (see code below)
  • Copy and paste the Render(ref XmlTree tree), and findMediaLink(Media dd, string nodeLink) methods from loadMedia.cs into your new class
  • Modify the findMediaLink(Media dd, string nodeLink) method to get the Guid from your custom media type, and check if it is equal to p.PropertyType.DataTypeDefinition.DataType.Id (see code below)

 

Here's the class:

    public class MediaTree : loadMedia
    {

        public MediaTree(string application) : base(application) { }

        public override void Render(ref XmlTree tree)
        {
            Media[] docs;

            if (m_id == -1)
                docs = Media.GetRootMedias();
            else
                docs = new Media(m_id).Children;

            foreach (Media dd in docs)
            {
                XmlTreeNode xNode = XmlTreeNode.Create(this);
                xNode.NodeID = dd.Id.ToString();
                xNode.Text = dd.Text;

                // Check for dialog behaviour
                if (!this.IsDialog)
                {
                    if (!this.ShowContextMenu)
                        xNode.Menu = null;
                    xNode.Action = "javascript:openMedia(" + dd.Id + ");";
                }
                else
                {
                    if (this.ShowContextMenu)
                        xNode.Menu = new List<IAction>(new IAction[] { ActionRefresh.Instance });
                    else
                        xNode.Menu = null;
                    if (this.DialogMode == TreeDialogModes.fulllink)
                    {
                        string nodeLink = findMediaLink(dd, dd.Id.ToString());
                        if (!String.IsNullOrEmpty(nodeLink))
                        {
                            xNode.Action = "javascript:openMedia('" + nodeLink + "');";
                        }
                        else
                        {
                            xNode.Action = null;
                            xNode.DimNode();
                        }
                    }
                    else
                    {
                        xNode.Action = "javascript:openMedia('" + dd.Id.ToString() + "');";
                    }
                }
                xNode.HasChildren = dd.HasChildren;

                if (this.IsDialog)
                    xNode.Source = GetTreeDialogUrl(dd.Id);
                else
                    xNode.Source = GetTreeServiceUrl(dd.Id);

                if (dd.ContentType != null)
                {
                    xNode.Icon = dd.ContentType.IconUrl;
                    xNode.OpenIcon = dd.ContentType.IconUrl;
                }

                tree.Add(xNode);
            }
        }

        private static string findMediaLink(Media dd, string nodeLink)
        {
            TheFarm.Umbraco.Controls.MultiMediaUploadDT mmDT = new TheFarm.Umbraco.Controls.MultiMediaUploadDT();
            Guid farmUpload = mmDT.Id;

            Guid uploadGuid = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
            foreach (Property p in dd.getProperties)
            {
                if ((p.PropertyType.DataTypeDefinition.DataType.Id == uploadGuid || p.PropertyType.DataTypeDefinition.DataType.Id == farmUpload) && !String.IsNullOrEmpty(p.Value.ToString()))
                {
                    return p.Value.ToString();
                }
            }
            return "";
        }

    }

 

 

Note: For this to work your custom media class must contain a Guid.

eg.

        public override Guid Id
        {
            get { return new Guid("{12345678-ABCD-EFGH-IJKLM-NOPQRSTUVWX}"); }
        }

 

Now go to the database and edit the umbracoAppTree table.

UPDATE umbracoAppTree
SET treeHandlerAssembly = '<your assembly>',
treeHandlerType = 'Umbraco.MediaTree' /* We called ours MediaTree */
WHERE treeAlias LIKE 'media'

 

That's it.

 

 

 

Posted on 3/4/2009 7:41:00 PM by AnthonyDang

Permalink | Comments (2) | Post RSSRSS comment feed |

Categories: Technology

Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Linq to Umbraco

Intro

We've been working on 3 larger Umbraco sites in which we've implemented our own Linq to Umbraco strategy. It's a fairly simple strategy, it doesn't involve custom expression trees or anything, it simply leverages Linq to Xml, IEnumerable<T> and extension methods. In simple terms, we basically convert Xml nodes into our own objects which we can then run typed Linq queries against. Since the performance of deserialization of this Xml into objects was one of our concerns, we implemented Microsoft's Policy Injection framework to handle the caching of our Umbraco objects which works really well (more on this later). Here's a quick example of what this allows you to do with Umbraco data (in this case Umbraco is storing information about events, such as festivals, etc...)

var todayEvents = (from e in GetEvents()
                               where e.FromDate.Date == DateTime.Now.Date
                               select e).ToList();

The source code is available here: LinqUmbraco.zip (566.35 kb).

Background

In order for this to work, there is a bit of setup involved. The way that we've gone about this implementation is by defining a data model for each Document Type that you want to be able to use in this framework. In this example, Umbraco will need to be setup with a few Document Types: Event, EventComment, EventOrganizer, EventsContainer. I've included the definitions of these doc types in the source code so you can easily import them. For an event model, we would create an interface:

public interface IUmbEvent : IUmbracoItem
    {
        System.Collections.Generic.List<UmbEventComment> EventComments { get; set; }
        string EventTitle { get; set; }
        DateTime FromDate { get; set; }
        string FullDescription { get; set; }
        string ShortDescription { get; set; }
        bool ShowInListing { get; set; }
        DateTime? ToDate { get; set; }
    }

You'll notice this interface extends IUmbracoItem which I've defined in our code library. It contains all of the basic properties of an Umbraco node:

 public interface IUmbracoItem
    {
        DateTime CreatedDate { get; set; }
        int CreatorId { get; set; }
        string CreatorName { get; set; }
        int Id { get; set; }
        int Level { get; set; }
        System.Collections.Generic.Dictionary<string, string> NodeData { get; }
        string NodeName { get; set; }
        int NodeType { get; set; }
        string NodeTypeAlias { get; set; }
        int ParentId { get; set; }
        string Path { get; set; }
        int SortOrder { get; set; }
        int? Template { get; set; }
        DateTime UpdateDate { get; set; }
        string UrlName { get; set; }
        string Version { get; set; }
        string WriterName { get; set; }
    }

Next I've created a class that implements this interface called UmbEvent which extends UmbracoItem(which in turn implements IUmbracoItem). The constructor function of these objects are what does the deserialization:

public UmbEvent(XElement x)
            : base(x)
        {
            //Get the from date and use the DateConverter to convert it.
            //If the returned date is MinValue, then the value in Umbraco has not actually
            //been set and since it is mandatory, we'll throw an Exception.
            FromDate = x.UmbSelectDataValue<DateTime>("FromDate", DateConverter);
            if (FromDate == DateTime.MinValue)
                throw new Exception(string.Format("The node with id {0} does not have a start date set", this.Id.ToString()));

            //Get the ToDate using a NullableDateTimeConverter
            ToDate = x.UmbSelectDataValue<DateTime?>("ToDate", NullableDateTimeConverter);

            EventTitle = x.UmbSelectDataValue("EventTitle");
            ShortDescription = x.UmbSelectDataValue("ShortDescription");
            FullDescription = x.UmbSelectDataValue("FullDescription");
           
            //Get the ShowInListing using the IntConverter since the value stored in Umbraco is
            //an integer, not a boolean.
            ShowInListing = x.UmbSelectDataValue<int>("ShowInListing", IntConverter) == 1;           
           
            //Select all child "node" nodes that have a node type alias
            //of "Event Comment" from the current element, deserialize them
            //to UmbEventComment objects, and store them in our List property.
            EventComments = x.UmbSelectNodes()
                .UmbSelectNodesWhereNodeTypeAlias("EventComment")
                .Select(n => new UmbEventComment(n))
                .ToList();           
        }

In the code for the UmbracoItem class are some helper methods for data conversion so exceptions are not thrown and that data is converted properly. 

The next step is to setup the data service layer. I generally create a different service class for each model and in this example we'll have IUmbEventService interface with an UmbEventService class defined as:

public interface IUmbEventService : IUmbracoService
    {

        int CreateEvent(IUmbEvent cqEvent);
        void UpdateEvent(int eventId, IUmbEvent e);
        List<IUmbEvent> GetEvents();
        IUmbEvent GetEvent(int eventId);
        DateTime LastEventDate { get; }

    }

Using the code

Service Layer

Most of the important work is done in the service layer. The underlying method that is called for retreiving events is the GetEvents() method which returns a List<IUmbEvent> object which we can use to query. This method will look up all events in the Umbraco xml cache, convert each one to an UmbEvent and return a list of these deserialized objects. I've created a bunch of Linq to Xml extension methods for use with Umbraco which I use to query the Umbraco xml cache. This makes querying Umbraco xml much nicer, easier and allows you to use System.Xml.Linq objects instead of the old XPath objects. Here's the definition of the GetEvents() method:

[CachingCallHandler(1, 0, 0)]
public List<IUmbEvent> GetEvents()
{

    Console.WriteLine("Looking up and caching all published events...");

    //Lookup the event container node in Umbraco
    XElement xNode = UmbXmlLinqExtensions.GetNodeByXpath(EventContainerXPath);

    var eventData = xNode
        .UmbSelectNodes() //selects all descendant "node" nodes
        .UmbSelectNodesWhereNodeTypeAlias(EventNodeTypeAlias) //selects nodes of a certain alias
        .Select(x => new UmbEvent(x)) //This does the object conversion
        .Where(x => x.FromDate != DateTime.MinValue); //ensure we don't return events with no start date

    return eventData.Cast<IUmbEvent>().ToList();
}

Now that this method is create, we can just query the result of the method to find Events by whatever criteria we've defined in the IUmbEvent interface. For example, the GetEvent method body is quite simple:

public IUmbEvent GetEvent(int eventId)
{
    var myEvent = m_This.GetEvents()
        .Where(x => x.Id == eventId);

    return myEvent.SingleOrDefault();
}

To expose my service layer classes, i have a service factory class that creates new instances of each service type when requested. This makes it easy to call services from code since there's always one point of entry.

Calling the services

I've included a class called Tests which calls the methods of the event service. With the above framework in place, using the code is extremely easy:

List<IUmbEvent> events = m_Factory.EventService.GetEvents();

or

IUmbEvent e = m_Factory.EventService.GetEvent(LookupEventId);

Also in the source code are service methods to create and update Umbraco nodes. If you're not familiar with how to do this, this will show you a fairly easy way to get the job done. The CreateEvent method actually checks to see if a "Pending" event organizer node is there and if not it creates one and then creates new unpublished events under this node.

Running the tests

I've created a simple ashx handler that you can setup in your Umbraco project to test this data layer. You'll need to build the solution and copy the DLL files over from the bin folder of the UmbracoData project into your Umbraco bin folder (don't copy over the Umbraco DLLs if you don't want to ... these are Umbraco 4 DLLs). Then add an HttpHandler to your web.config:

<add verb="*" path="datatest.ashx" type="UmbracoData.TestHandler, UmbracoData" />

You'll have to make sure Umbraco is setup for this project so you'll need to: 

  • Import all of the document types
  • Create a node of type "EventsContainer" called "Events" under the root content node

Now you can navigate to datatest.ashx which will allow you to run the tests. If you want to step through the code, just Attach to your Asp.Net process with the solution open.

Policy Injection

As I mentioned before, performance will be a factor if for every event query, we need to deserialize every event xml node into an object. This is where caching comes in handy. We use Policy Injection quite a bit to do caching and logging in our applications as it makes these tasks incredibly easy. Policy Injection is a simple form of AOP (Aspect Oriented Programming) and is part of Microsoft's Enterprise Library. You'll see that this method is attributed with the CachingCallHandler which is going to cache the output of this method for 1 hour in this case. In each subsequent call to this method Policy Injection will intercept the call and determine if it has been cached, and if so, it will simply return the cached results and cancel the execution of the method.

In order for Policy Injection to work, you need to either create a new service class or wrap and existing service class the with Policy Injection. As i mentioned before I use a service factory to expose all of my service classes and in this class, it creates each service with Policy Injection:

public class ServiceFactory
{
    public IUmbEventService EventService
    {
        get
        {
            return PolicyInjection.Create<UmbEventService, IUmbEventService>();
        }
    }       
}

There is a catch!! You'll notice in the above code snippet that defines the GetEvent method uses the syntax: m_This.GetEvents(). This is because we need a reference to the event service class wrapped in Policy Injection inside the event service class.... confusing in know. This is because the Policy Injection framework is the only thing that knows anything about the CachingCallHandler attribute and if we call GetEvents inside one of the methods of the UmbEventService, then Policy Injection is actually not playing any part of that method call. To get around this, we define an internal property in the UmbEventService class of type IUmbEventService and in the constructor function, we wrap this instance in Policy Injection and assign it to this property:

public UmbEventService()
{
    //Ensure our internal object is wrapped in PolicyInjection
    m_This = PolicyInjection.Wrap<IUmbEventService>(this);
}

/// <summary>
/// We declare this variable as a "trick" to ensure that PolicyInjection
/// is still used when we call internal members of this class.
/// For example, any method of UmbEventService that calls GetEvents() will need
/// to call m_This.GetEvents() to ensure that it returns the cached data
/// and does not re-execute the code in body of the method.
/// </summary>
IUmbEventService m_This;

Another point of interest is that i've included an Umbraco action handler to refresh the Policy Injection cache whenever a node is published.

The source code is available here: LinqUmbraco.zip (566.35 kb).

Posted on 2/24/2009 12:38:00 PM by Shannon Deminick

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: Technology

Tags: , , ,

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Linq + Unity + AOP = Fun

I've recently had some time to look at using Dependency Injection alongside of Linq to SQL to manage the DataContext. Because of the way that Microsoft made Linq to SQL, it's not very easy to use dependency injection properly with the DataContext because many of the members in this framework are not interfaces or cannot be instantiated directly from code. Type mocking frameworks can be used to mock these objects but i wanted to see if there was a way around all of this. I've posted a project on the CodeProject website here. A few tricks had to be implemented like creating an interface for the DataContext (IDataContext) and exposing a new property called GetITable exposing a new interface called IEnumerableTable<>. This way, you can resolve IEnumerableTable's from the IDataContext instead of resolving a System.Data.Linq.Table from the GetTable<> method (which you would never be able to implement in a custom DataContext class). Because the IEnumerableTable<> interface is IEnumerable<T> itself, you can run all your normal Linq queries against it as per normal. IEnumerableTable<> also implements ITable so you can perform all of the normal Linq to SQL table methods (i.e. InsertOnSubmit, etc...) on the resolved object.

To get this framework setup and working there's quite a few things you need to build, but it's quite a fun exercise. Included in the source is a custom DataContext called XDataContext which turns the data store into XML files instead of database tables and still uses the Linq to SQL entities that are generated. You can simply just map the IDataContext to any custom data context using the Unity (Microsoft's dependency injection framework) configuration. I've also implemented PolicyInjection into this framework as it is extremely easy to do now that all of the objects are interfaced already. Now it's too easy to cache and log calls to methods.

There's a complete description of everything in the article.

Posted on 2/20/2009 1:28:00 PM by Shannon Deminick

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: Technology

Tags: , , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 
Copywrite © 2008 The Farm Digital