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.

Print | posted on Friday, June 08, 2007 10:59 AM

Feedback


Gravatar

# re: Setting up Windsor for auto registration of components 6/8/2007 12:20 PM 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.


Gravatar

# re: Setting up Windsor for auto registration of components 6/8/2007 1:35 PM 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.


Gravatar

# re: Setting up Windsor for auto registration of components 6/8/2007 1:47 PM 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...


Gravatar

# re: Setting up Windsor for auto registration of components 6/8/2007 7:43 PM 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?


Gravatar

# re: Setting up Windsor for auto registration of components 6/8/2007 7:56 PM Ayende Rahien

The "home.controller" convention.
I just looked at the code, and it looks like it i not actually need, though.


Gravatar

# re: Setting up Windsor for auto registration of components 6/12/2007 4:13 AM 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.