WindsorBootstrapper for Prism2

For a large, enterprise application at work, I have been utilizing the Prism (CompositeWPF) framework. The application is still in progress, so I am unable to discuss it’s nature too much in detail. However, Prism has been a large help in getting the base framework for the application laid out and constructed. After finishing a few other tasks, I decided to check the status of the CompositeWPF project and look for any updates. That day just happened to coincide with Prism2′s latest release. The update sounded appealing, so I started the process of moving everything over to it.

While moving over to the February 2009 release of Prism2, I ran into issues with a few of the pieces I was using from the CompositeWPFContrib project. For example, the Windsor container bootstrapper had not been updated for the new release of Prism, leading to many problems. In order to fully move over to Prism2, I’d need to either give up on using Windsor, or create a new bootstrapper for Prism2 capable of working with Castle Windsor. Choosing option 2, I started with the bootstrapper for Unity and with the base Castle Windsor implementation for ServiceLocator, then modified them quite a bit. The final results that I ended up with will be posted below.

One significant difference between Castle Windsor and Unity came to light while writing and testing these new classes. If a specific instance of a class that hasn’t been registered into the container is requested from Unity, Unity doesn’t complain and just goes ahead and injects what is needed. Castle Windsor, on the other hand, will throw an exception complaining that the component wasn’t registered. Both seem like valid approaches, but I wanted to make the transition as simple as possible. So, to avoid changing too much of the logic found within Prism2 (and the bootstrapper), I added a “ResolveEx” extension function to IWindsorContainer. If a specific class is requested through this function that isn’t in the container, it will register it as transient and return an instance. I also changed the ServiceLocator implementation for Castle Windsor to use “ResolveEx” if a key is not passed in.
Read the rest of this entry »

Castle ActiveRecord and Fluent Create/Update/Save

I came up with an interesting idea the other day at work involving some work I had been doing with Castle ActiveRecord. I am using (a modified) GeneratorStudio to produce ActiveRecord partial classes based on a database schema that I have. All of my code additions go into another set of partial class files so that I can regenerate the base classes whenever I need to.

However, there are many times when I need to find a specific item, and if it isn’t found, I need to create a new one. After this, it is used for yet another item. So essentially, the item has to exist before the code can continue. This is where my slightly clever (if I can call it that) idea comes into play.

I will be using part of the example Post class from as a basis for the new idea:

public class Post : ActiveRecordBase<Post>
    private int id;
    private String title;
    public Post()
        created = DateTime.Now;
    public int Id
        get { return id; }
        set { id = value; }
    public String Title
        get { return title; }
        set { title = value; }

For all of my unique indexes, I create additional static helper methods that allow retrieval by those constraints. Let us assume that Title is a unique index; that is, there can only be a single post with a specific title. Then the following function becomes valid (in the Post class):

public static Post GetByTitle(string title)
    return FindOne(Restrictions.Eq("Title",title));

And here is my little idea for making a small fluent addition (to the Post class):

public Post CreateFluent()
    return this;

A function similar to this would hopefully work for CreateAndFlush, Update, UpdateAndFlush, Save, and SaveAndFlush as well. Once all of this is in place, I now have many new options for dealing with items that need to exist or be updated before they can be used. I find the fluent-like style of this to be easy to read while working through code:

var post = Post.GetByTitle("42") ?? new Post { Title = "42" }.CreateFluent();
// do something important with post

Since Post.GetByTitle(string title) will return null if the post cannot be found, the null coalescing operator (??) takes care of automatically running the second half and creating the new Post if a Post with the specified title couldn’t be found. I’m still testing this fully to see how well it works, but I’ll update here once I get concrete evidence of its functionality.

EDIT: I’ve been using this for the last few weeks and I have not run into any issues with it. It looks pretty slick in the code, too.

New Theme, Updated Code

I’ve decided on a theme for my blog that I feel comfortable using without tweaking the design too much more. I’ll still be making minor tweaks and enhancements, but at least I won’t be devoting all my blogging time to making a design. Since I’m mostly content with it, I’ll be able to devote a larger portion of my time to actually writing new content.

The theme I chose, though, was only written and available for WordPress 2.5. I know how to work with PHP and HTML/CSS, so I jumped right in to make the modifications necessary to support the new WordPress 2.6 and 2.7 features. WordPress 2.7 added an entirely new comment loop and threaded comments, therefore most of the comment code had to be rewritten to support it. In addition to that, a new function was added to get the classes used for styling each entry:

The post_class() outputs the class=”whatever” piece for that div. This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds “sticky” for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways.

Besides the required changes to make the theme work fully with WordPress 2.7, I also added in a few personal features. First, I made the H1 on the pages dynamic. It was originally constructed so that the title of the blog appeared in the H1 for every single page. I have seen it written multiple times that the title of the blog should only be in an H1 on the main page of the blog. On the individual content pages, the title of the content (post or page) should be contained within an H1. This is supposed to help with SEO. Second, I added my Twitter loading javascripts to the footer. With the load script in the footer instead of in a widget, only a very minimal portion of my site doesn’t load if Twitter goes down. Third, I added my Google Analytics code to the footer as well.

Here's a screenshot of the new threaded comments. Notice the 'Reply' link on the left side if a comment can be replied to.

Here's a screenshot of the new threaded comments. Notice the 'Reply' link on the left side if a comment can be replied to.

I would like to make a settings panel for administering options for the theme, such as my new Google Analytics and Twitter support. I feel that this would be useful for myself, but possibly more beneficial to others. If there is sufficient demand (or any :) ), then I may try to contact the authors of the dark theme for WordPress to see if I can release my own version. If I do that and get permission, I will definitely be adding a settings panel with a multitude of options.

Reviving My Blog

With the start of another year, and the dawn of a new era for the world, this seems like a good time to restart my blog. But this time, I will do so with a commitment to myself. It’s time to get past the excuses I have so easily found in the past and begin to write entries for my blog.

if you don’t write something, then there will never be anything written

For a long while, I believed that content was the most important aspect of a blog. I became stuck on the idea that I needed to write incredibly thought provoking entries and ended up writing nothing. However, if you don’t write something, then there will never be anything written. (This sounds incredibly obvious as I write it down, but hey, I wrote it down.) This has led me to the conclusion that a new methodology for writing blog entries is needed. As a result, there may be an overwhelming multitude of smaller entries interspersed by a few larger entries. As long as I keep the flow going, though, I hope that I will find the resolve to continue this for a long time to come.

My decision to start blogging again was spurred from many sources. While working on various projects, I have discovered that most of the time, I find almost all of the answers I need within blogs. I’ve been using blogs long enough now, without contributing, that I feel it is my turn to give a little back. One day, I stumbled across a question on StackOverflow that hit home: How can you tell whether you’re ready to start your own blog?. After reading that, I knew that I had to make the time and get started, regardless of work schedule. Waiting for work to quiet down was only going to delay it even more.

I picked a schedule for posting after following a little advice from an entry by Jeff Atwood, How To Achieve Ultimate Blog Success In One Easy Step:

When people ask me for advice on blogging, I always respond with yet another form of the same advice: pick a schedule you can live with, and stick to it. Until you do that, none of the other advice I could give you will matter. I don’t care if you suck at writing. I don’t care if nobody reads your blog. I don’t care if you have nothing interesting to say. If you can demonstrate a willingness to write, and a desire to keep continually improving your writing, you will eventually be successful.

The personal posting schedule that I am going to strive for is at least one post per week. I can only imagine that at the beginning there will be a series of small ‘testing the water’ posts as I attempt to get my blog looking like I want. I also would hazard a guess that some (or a lot) of my grammar will be malformed and a few spellings will be wrong. My writing skills have gotten a little rusty, but through continued perseverance, I hope to improve that.

Finding and getting ideas out may be a little difficult at the onset since I’m not sure what to write about or where to start. To achieve this, I’ve thought up a couple of ideas that I believe will help me to find the quantity of ideas I need to get started. First, I’m going to keep a small notebook beside my bed so that as I’m falling asleep, I can write down any ideas that come to mind. I have a tendency to become more reflective just before I become too tired to think. Second, if I’m at work and I think of an idea or solve a problem that I think would make a good post, I’m going to send a small email reminder to myself to jog my mind later. A filter that checks for a specific word in the subject and tags the email appropriately would probably be very useful for this. I don’t have any free (or flexible/20%) time at my busy current job, so I won’t be writing any blog entries during those hours. If the topic specifically applies to work and I get approval to write a blog entry on company hours, I’ll tag or denote the post in some obvious way in the interest of full disclosure.

Politics: The Foundation of the U.S. Government

I just found a really interesting and enlightening article that was written by a 17 year old law student. The title of the article is “The Great Pillars of Our Government”. The entry talks about some of the things that the founding fathers of this nation were saying and has several excellent quotes on it. One of my favorite quotes from the page is the one below by Robert Winthrop (I retrieved the full paragraph of the quote from Google):

All societies of men must be governed in some way or other. The less they have of stringent State Government, the more they must have of individual self-government. The less they rely on public law or physical force, the more they must rely on private moral restraint. Men, in a word, must necessarily be controlled either by a power within them, or a power without them; either by the word of God, or by the strong arm of man; either by the Bible or by the bayonet. It may do for other countries and other governments to talk about the State supporting religion. Here, under our own institutions, it is Religion which must support the State. (from: Addresses and Speeches on Various Occasions, By Robert C. Winthrop, p. 172)

This varies from what I would normally talk about, but I tend to be a conservative, and I like to at least stay informed about the government. This is from a long time ago, but I think it gives perspective to things that are happening in the current world. As a side note, I think that the next presidential election will be very interesting to watch, as I believe that the running of the candidates will get very heated.

Google Apps

I just found that you can get Google Apps for free (standard edition) for any domain that you may own. I just set it up for my domain and I think it’s pretty cool looking. You can get Gmail on your domain, some simple webpages, a google ig start page (partner page or something like that), calendar, and docs for your own domain. For the standard edition (free one) you can have like up to 100 users and each user gets 2gb of mail storage.

The really cool thing is that Google has the MX entries to set the mail up and a place to redirect all the other domain settings to. All i had to do was set up the Google Apps thing, then log into my domain administration page and enter the entries that the step by step instructions say to.

The only downside that I see at the moment is the simplicity of the webpages that you can make. I didn’t really look that far into it, but as far as I saw, they are pretty basic pages. If you have a domain that isn’t being really used or pointed to anything, or you just want a cheap way to get something up and have a nice mail system, Google Apps is definitely something to check into.

Safari. On Windows?

For anyone who has yet to make the full switch to Mac (myself included), it looks like Apple is releasing Safari for Windows. It’s still in beta, but from the Apple site, it looks like it’s supposed to be much faster than Internet Explorer 7 and Firefox. I own a Mac (Powerbook G4 laptop) and when I’m using it, Safari is my browser of choice. Now I may have a new browser to use while I’m working on my desktop (I currently use Firefox 2). Once I give it a few days testing, I’ll have to report back how it goes. Anyways, here the link to the page about Safari 3 and the download page.

First post. Woo!

Well, now that I have something presentable up for my template, it’s time for the standard first post. My first posts are generally very short and tend to end up looking something exactly like this. Rather than drag it on too long, I’ll just end it here and let everyone look at my new template :)