Keeping Configurations Happy

I just spent about 20 minutes trying to figure out a very dumb problem with my configuration files.

 The way I have my configuration setup for my projects is becoming a little cumbersome. I would interested in any other ways people have of accomplishing this because I am ripe for change.

In my folder structure I have it setup like so:

Now, above this folder I have the branches and tags folders, as well as a docs folder that holds any documents, psd files etc so I don’t have to branch/tag any large original files all over the place and increase the size of the svn repository.

As you can see the “lib” folder is any dependencies I have on my projects. Castle, SqlCe and log4net/nhibernate is in the root. In addition I have a app_offline.htm under app_offline that gets copied to the deployment root before the deployment happens, and then deleted after it is finished. Everyone should be doing this!!

Under the “configuration” folder are the following files:

  • site.deployment.config
  • site.desktop.config
  • site.staging.config

Herein lies the problem…All that is in these files is AppSettings that change depending on where the project is at, for filepaths, specific files etc… If I also develop from a laptop there would be a site.laptop.config that would contain appropriate paths to save files to etc… The appropriate .config file is copied to whereever the app.config is and renamed to site.config, then I tell TortoiseSVN to ignore site.config so that it doesn’t get placed into the project root. With NAnt, I have a task that copies that config file into the right place and renames it to site.config. I know what your’re thinking here, “Well you could use XmlPoke”, which I do for certain things but I can’t always use xmlpoke when I am running on my machine etc..

This is all grand and peachy for myself being the only developer, but then what happens as I bring on more developers? Then I need site.username.desktop.config, for each and every developer. This becomes a real PITA.

I know there has to be a better way to accomplish this other than the way I am doing it now. It has worked so far but it’s becoming a pain to change a setting and then copy the site.whatever.config to the right place and rename it to site.config. I guess I could use pre/post build events but again this seems like to much of a pain.

Does anyone have a better way of doing this? I can’t stand this method anymore. I need something more effecient

Windsor Container Factory Facility

This is a real cool facility that I just used in my Hybrid CMS. There is a full in depth walkthrough on BitterCoder’s Blog here but I will describe how I used it in this blog post.

I needed to be able to have the kernel instantiate a specific implementation of IAuthService. This Interface has a couple of method definitions, but most important it had the Authenticate() method. The idea behind this is that I can swap out IAuthService and change the way a user is authenticated. At the moment Active Directory and Database is supported.

So in the whole architecture I have the following classes/interfaces

  • IAuthService
  • DbAuthService : IAuthService (component id: db.authService)
  • AdAuthService : IAuthService (component id: ad.authService)

In the Castle config section for Windsor, they have the following component Id’s listed above. Both of these component declarations have factory=authServiceFactory which activation of the components are deferred to at runtime.

In the AppSettings section I have an Application Setting called authStore=db.authService, which just has whichever component will be used for authentication.

Here is the code for AuthServiceFactory to give you an idea how the AuthService’s are returned from the kernel:


public class AuthServiceFactory : IAuthServiceFactory 


private IKernel _kernel;public AuthServiceFactory(IKernel kernel) { 

_kernel = kernel; 


protected string AuthStoreType 

{ get { return ConfigurationManager.AppSettings["authStoreType"]; } 


public IAuthService Create() 


return (IAuthService)_kernel.Resolve(AuthStoreType, typeof(IAuthService)); 



Pretty cool huh? Now if I want to introduce a new method of Authentication I only need to add the component to the config file, make an implementation and select it in the AppSetting. Very flexible! =)

Good example of Domain Services

Here is a good example that Chris Richardson posted in response to one of my questions of the DDD Yahoo! Group. If you haven’t done so already you should take a look at his presentation at SpringOne in June. It goes over all the major DDD topics and gives a really good description of DDD in general.

This is the same manner that I try to use Domain/Application Services although I have found that it’s easy to go overboard with a Service layer and IMO should only be implemented when necessary. There is really no reason to have a Service class that just wraps a Repository. It’s just extra code that needs to be maintained. In Chris’s exmaple though, he illustrates how a Service would retrieve data from one or more Repositories, performs some small amount of work and thats it.

I will be posting more on this later. Just wanted to share the example that I saw. Cheers!

Build, Train and Listen

This afternoon I conducted a training for a number of teachers that will be using my new website CMS to perform website updates.I know alot of developers groan at the thought of talking to the users of their software. People truly are stupid in numbers. Even I don’t like it all that much. That being said, I still force myself to do these trainings from time to time.

Normally we have three other people that actually perform the trainings, but when a number of new features come out for the first time, or we are trying something new I setup a new presentation and talk before all the people. You would be suprised how beneficial this can really be to the health of the project. Now, there is definately alot of extra chatter going on in the form of complaining, or a user that can’t figure out whether to right click or left click, but as a whole you can instantly see trends arise in what people are trying to do that they can’t do.

Amazingly, the more of these I go to you consistently see the average person do the same set of things to the software. This helps so much in jotting down notes on how to make this easier or make that easier. I can get quality feedback in 90 minutes that would take me much longer to retrieve from Reviewers. Unfortunately you do have to filter out a lot of extra suggestions that is irrelevant, like the one user that wants it to everything for them just outside the realm of reality.

Being in a school district and making software for internal use only definately has it’s benefits so this probably doesn’t apply to all situations but it should still be considered. Maybe along the lines of telling a user of the system to user a piece of software like normal and you watch them go about their normal work. The desire here, at least for me is to eliminate the pain they have to deal with when I am not present. My aim is to make it as easy as possible for that user to utilize my software so that they will recommend to management that we should continue working because of this or that, or they should renew my contract etc…

Throughout the whole month of September I will be doing at least one training a week if not twice at two school per week. By the end of the month we should have the majority of the schools out of the way. Hopefully then the teachers will stop pestering me =)

It is quite a task to attempt to bring about 1500 teachers up to speed with a new piece of software in a little over 2 months and also continue on with my normal duties. I think in the end the trainees will also train the trainer. Both parties are receiving. Cheers!

Testing MonoRail Controllers from Castle’s Trunk

Note: This post was on my old blog, but it is linked to and I wanted to move it to my new blog for future reference.Originally, Hammett placed a AbstractMRTestCase in the same namespace to facilitate testing of controllers. This class simulated a browser by supplying the user with access to session, request, response etc… This class didn’t work too well and was clunky to use. The guys at Eleutian came up with their own solution awhile ago that you can read here. This worked by mocking out everything that the Controller class needed using Rhino Mocks. This worked much better, although it was a little tricky to pull down and use yourself.
Enter BaseControllerTest! This works off of Eleutian’s example and makes the whole deal much easier. Here is an example of how you would go about using it.
First, Your Test Fixture must derive from BaseControllerTest. In this example I am testing a SearchController I made for CMS software:

public class SearchControllerTestCases : BaseControllerTest{}

Next, You must instantiate your Controller class. I do this in the SetUp method, as I am using the Controller in more than one test and I don’t want to violate the DRY principle:

public void SetUp()

_mocks = new MockRepository();

_searchService = _mocks.CreateMock();

_searchController = new SearchController(_searchService);

As you can see I am also passing in a mock of a Serivce that is provided by Windsor at runtime. Now we have created our controller and set everything up. Now we are ready to perform our first test. The following test Searches for a Teacher by their username. Note in the test that I make a call to PrepareController. This sets up the controller with the specified area, controller and action. Take a gander at the code for BaseControllerTest class here and it will give you a much better idea of what PrepareController is doing. All it does is setup the IRailsEngineContext by creating instances of mock classes that will respond to your test. Here is the code in my test to perform SearchForTeacher():

[Test]public void CanSearchForTeacher(){IList teachers = new List();PrepareController(_searchController, "", "Search", "FindTeacher");string teacherName = "username";using (_mocks.Unordered()){Expect.Call(_searchService.FindTeacher(teacherName)).Return(teachers);}_mocks.ReplayAll();_searchController.FindTeacher(teacherName);_mocks.VerifyAll();}

So the only mock expectation I need to setup here is for SearchService.FindTeacher that is called when FindTeacher() is called on the controller. If I had values that needed to be set such as PropertyBag values, or CurrentUser. All you need to do is just set them by using the Context variable available through BaseController test like so:

[SetUp]public void SetUp(){MockRepository _mocks = new MockRepository();_webSiteManageController = new WebSiteManageController();_user = _mocks.CreateMock();PrepareController(_webSiteManageController, "manage", "WebSite", "List");Context.CurrentUser = _user;}

Note where I am setting Context.CurrentUser as it is accessed through this Controller on the AuthorizationFilter I have setup on the WebSiteManageController class. This way, everytime the AuthroizationFilter is run, it will return true to allow access to the underlying controller.Hopefully that gives you a jump start on using Castle’s new Controller Test support! Have fun!

DDD Yahoo Group

If you haven’t seen it already, everyone interested in Domain Driven Design should check out the Yahoo Discussion group found at are many good discussions going on here. As well as alot of people that are actively involved in the DDD community. One of the most beneficial discussions I have seen in the last week is a large thread on aggregates. I learned a great deal about things I was overlooking when it came to aggregates in a domain model.Check it out!