Oren posted quite a while ago on a little DSL for configuring Castle Windsor using Boo. He has creatively titled this DSL Binsor. I had previously used the Batch Registration facility because I did not want to maintain XML configuration for 75+ components. Since I am revisiting the project now and updating to the trunk Rhino Tools I thought I would try out Binsor. Below is the complete script I use to configure MonoRail with Windsor, configure logging, wire up the NHibernate Repository, load all of my MonoRail Controllers/ViewComponents, and all supporting components. This script is derived from the Hibernating Forums binsor script and the source for the Batch Registration facility.
import System
import System.Reflection
import Castle.Facilities.Logging
import Castle.MonoRail.Framework
import Castle.MonoRail.WindsorExtension
Facility( "rails", RailsFacility)
Facility( "logging", LoggingFacility, loggingApi: "log4net", configFile: "My.Product.log4net")
Component("repository", IRepository, NHRepository)
Component("unitOfWorkFactory", IUnitOfWorkFactory, NHibernateUnitOfWorkFactory)
coreAsm = Assembly.Load("My.Product.Core")
for type in coreAsm.GetTypes():
if typeof(Controller).IsAssignableFrom(type):
Component(type.Name, type)
elif typeof(ViewComponent).IsAssignableFrom(type):
Component(type.Name, type)
elif type.IsDefined(typeof(CastleComponentAttribute), false):
compAttr = type.GetCustomAttributes(typeof(CastleComponentAttribute), false)[0] as CastleComponentAttribute
Component(compAttr.Key, compAttr.Service, type, compAttr.Lifestyle)
posted @ Tuesday, June 19, 2007 7:28 AM