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
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.
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)
{
}
}
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.
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...
Not sure I'm following you here. What convention?
The "home.controller" convention.
I just looked at the code, and it looks like it i not actually need, though.
Perfect timing Ayende! I was just looking at how unnecessarily big my windsor config file was.
Comment preview