Question

I am new to using Castle.Windsor for IoC. Right now, I want to register UI elements to plug into certain points within the main form (SWF). Thus I have tree nodes to inject those elements into, such as Application.MainWindow.Navigation.MyModule. Using

container.Register(Component
   .For<System.Windows.Forms.Control>()
   .ImplementedBy<MyControlClass>()
   .Named("Application.MainWindow.Navigation.MyModule") // this is the plug-in path
   .LifestyleTransient());

should do it up until here.

Inside the applications main form I need to access the controls inside the container and evaluate the path they are stored at. But as far as I see, by iterating over

container.ResolveAll<Control>()

I won't get the path set as a name for each UI element.

Is there any way to access the path or maybe even a better way to achieve this (with Castle)?

Thanks in advance. :)

Was it helpful?

Solution

You can customize how a component will be created by Castle.Windsor with OnCreate You could define a property for your class MyControlClass named Path and init it like this (psuedocode)

container.Register(Component
    .For<System.Windows.Forms.Control>()
    .ImplementedBy<MyControlClass>()
    .Named("Application.MainWindow.Navigation.MyModule") // this is the plug-in path
    .LifestyleTransient()
    .OnCreate((myControlClass) => myControlClass.Path = "Application.MainWindow.Navigation.MyModule")
);

This way you can customize the creation of your component during registration. You can use a list of actions which will be applied between resolution and retuning your component to your code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top