Ayende @ Rahien

Unnatural acts on source code

Setting up Windsor for auto registration of components

I was asked how to do this, but this is frightfully simple:

controllersAsm = Assembly.Load("MyApp.Controlls")
for type in controllersAsm.GetTypes():
	if typeof(BaseController).IsAssignableFrom(type):
		Component(type.Name, type)

This example is using Binsor, executable configuration can do some really nice things.

Another option would be to build a facility to do this, which is about the same amount of code.

Comments

Jeremy Miller
06/08/2007 09:20 AM by
Jeremy Miller

That's only half the battle though. How do you retrieve these things later? IoC.Resolve<What?>(?)

I don't use it as much anymore, but I've always done this kind of thing with StructureMap's attributes where I can specify the instance name.

Ayende Rahien
06/08/2007 10:35 AM by
Ayende Rahien

Well, it depends on how you want to handle that.

Right now I have to use web forms, so the View has a public property with the right type, so when it is initialized, it ask the controller for the instance, and it gets that.

It looks something like this:

public class HomePage : BasePage

{

public HomeController Controller { get {} set { } }

public void Page_Load(object sender, EventArgs e)

{

 PoliciesRepeater.DataSource = Controller.GetPolicies();

 DataBind();

}

}

Using MonoRail, I need to make sure that the names that I register the component under will follow the MR convention, so MR will resolve them magically from the container.

joeyDotNet
06/08/2007 10:47 AM by
joeyDotNet

Yep, using the Windsor facility with MonoRail is a joy. Now if I could just find the time to start using Binsor for configuration. Sometimes my Windsor xml configs can get quite large. From what I've seen, Binsor can greatly reduce the size...

hammett
06/08/2007 04:43 PM by
hammett

Using MonoRail, I need to make sure that the

names that I register the component under will

follow the MR convention, so MR will resolve

them magically from the container.

Not sure I'm following you here. What convention?

Ayende Rahien
06/08/2007 04:56 PM by
Ayende Rahien

The "home.controller" convention.

I just looked at the code, and it looks like it i not actually need, though.

Dave Newman
06/12/2007 01:13 AM by
Dave Newman

Perfect timing Ayende! I was just looking at how unnecessarily big my windsor config file was.

Comments have been closed on this topic.