When Alex, Shannon and myself were putting together the list of
Umbraco 5 Gems for the CodeGarden 11 talk we had to make a decision
about what we would and what we wouldn't be able to cover. Since we
only had an hour and there are so many awesome hidden gems in
Umbraco 5 there was a number of things that simply didn't make it
into the presentation.
In this final part of the series we're going to have a look at
the remaining Gems, the last of the cool features from the Umbraco
5 CTP (but not the last of the cool features for Umbraco 5!)
Bendy Objects
In Umbraco 5 we're making quite extensive use of dynamic objects
to make it easier for people to work with the data that is being
generated from the Umbraco database, similar to the idea of
DynamicNode in Umbraco 4. But we realised that we needed a much
more powerful way that you could deal with dynamic objects and more
importantly, dynamic object graphs.
This is where Bendy comes in, the idea of Bendy (and in turn Bendy
Objects) is that you can turn any object, or any object graph, into
a dynamic object. With Bendy you can either make the objects
dynamic typed and use 'dot-notation' (entity.SomeProperty) to
access the data stored by that entity for a property or you can use
it like an indexer (entity["SomeProperty"]). What is also really
cool about Bendy is that is all lazy loaded so if you never access
a particular property the data will never be produced, and the same
goes for children and parent objects. This gives us high
performance within the API itself.
Expect to see more on Bendy as tutorials come out around working
with Umbraco 5 data.
WriteLockDisposable
Dealing with shared memory resources in multi-threaded
applications can be a bit of a pain and your only safe bet is to
use double
lock checking. With some improvements that have come as part of
.NET 4.0 we've been able to make this a bit simpler for developers
through a custom API we're exposing called WriteLockDisposable.
Essentially this creates a disposable object which you can then use
yourself to create singleton objects and not worry about having
thread locks occurring from accessing shared resources.
Mandate API
How many times have you written a check for an
ArgumentNullException, how about a generic ArgumentException? This
is something we do a lot in Umbraco 5. And I mean a lot!
Since we wanted a way which we could easily do the check in
the same way everywhere we've created an API which is named
Mandate. You use Mandate like saying Mandate.That(boolean, "message
when failing") and we'll handle the rest. We're even going to
support localizing the exception messages using the awesome new
localization framework. Mandate can be used for null checking or
boolean condition checking, giving a clean and common way to do
error raising.
DisposableTimer
Anyone who has tried debugging an internal error of Umbraco 4
will know just how hard it can be and when something breaks
internally it's very hard to describe to someone else. To address
this with Umbraco 5 there is a new API which is used to manage the
tracking of information when something internally is happening.
When you spin up a DisposableTimer a log message starts then you
can use the logging API add your own messages before the
DisposableTimer is disposed of. This means you can see what happens
between the start and finish making it very easy to see the what
happened in a particular scope.
Logging
As mentioned above we have a DiposableTimer in Umbraco 5 which
will help tracing what happens in a particular scope block which
you can do your own logging in. For logging we've gone with log4net
which is a very popular .NET logging API. To make it simpler to
work with we expose a LogHelper class which will help you get the
appropriate logger for your type.
Another really good feature of log4net is that through its
powerful configuration system we can control the logging very
finely, so when you deploy to a production server you can dial back
the logging to a minimal. If an error is happening in a specific
section of the application you can enable deeper logging for that
section than the rest of the site, etc.
Hopefully this means that finding errors within the core of
Umbraco 5 itself a lot easier.
Simplifying LINQ with QueryDescription
For a Hive Provider the ability to query is quite important and
the obvious query API is LINQ. The problem with LINQ (well with
Expression Trees actually) is that they are very complex and to
create your own custom provider that will be able to process an
Expression Tree into something that you can understand in your
provider is really quite complex.
In an effort to make it simpler for people to create their own
Hive Provider and have it queryable we've created an API in Umbraco
5 called QueryDescription so rather than receiving the Expression
Tree in its raw form Umbraco 5 will parse it into a
QueryDescription which you can then consume in a much simpler
manner.
This will give the power of LINQ to consumers of Hive Providers
yet a simple API to handle as a Hive Provider implementer.
PreValue's are overridable
Something we've noticed with the way users were using Property
Editors which had PreValues in Umbraco 4 was that the same Property
Editor would be used on multiple Data Types with only a change to a
PreValue or two. With Umbraco 5 we've decided to make this a bit
easier, rather than having to create multiple Data Types to change
a single PreValue you'll be able to override the PreValue
properties on the Document Type. This means that you can
create a Data Type which is your standard way with standard
PreValues, but on a special case you can change it to what's
needed.
The advantage of doing this is that if you want to create a larger
change to a Data Type you'll be able to do that in a single place,
rather than across multiple Data Types.
Examine is BACK
Examine the Lucene.Net search API which has been included since
Umbraco 4.5 will be making a return in Umbraco 5 but it's getting a
face lift. Instead of being an external API which has its own query
manner and such the new Examine version (ingeniously named Examine
2) will be an Umbraco 5 Hive Provider. Something
that we've been stressing in this blog series (and the Umbraco 5
Hive talks) is that the Hive isn't just about Nodes and Examine
will be living proof of this.
Additionally Examine will be taking a larger role in the way data
is handled in Umbraco 5, rather than being the primary Lucene.Net
API we're going to be providing a fast-read API to serving out the
published content in Umbraco, a new API powered by Examine.
And after all Examine 2 is just a Hive Provider so why couldn't it
be used in such a way to make the published content even
faster?
Providing functionality to pages
In Umbraco 4 you can put your own functionality behind a
template by creating a custom base type that the template inherits
from. With Umbraco 5 we wanted to offer similar capabilities but in
a MVC way, this means that we need to ensure that if you want to
create a Controller and Action then you can.
Well the good news that this will be possible in Umbraco 5,
allowing you to use the skills from standard ASP.NET MVC3
development for the most part. Rather than looking at the URL to
get the Controller and Action Umbraco 5 will look to the Document
Type Alias and Template Name. So if you have a Document Type with
the alias textPage you can create a Controller named
TextPageController. Immediately the Umbraco 5 rendering engine will
redirect all requests through the Index Action (assuming it
exists), allowing you to provide global changes to any page using
that Document Type. If you want to take it one step further you can
then create an Action on the Controller which has the same name as
a template, say Content (for the content template) which you then
have control over just that particular Document Type and Template
combination. This opens up a world of possibilities to say return
JSON from a Template rather than HTML but influencing the Action
Result returned from the Action.
Powerful huh!
And now we are at the end of our Umbraco 5 Gems series. We hope
that you've enjoyed reading about some of the more hidden and
unusual aspects of Umbraco 5 and can't want to get cracking with
it.