The following code is for demo purposes only.
Lets say i have 2 components (businessService, and dataService), and a UI class.
UI class needs a busi
Yes, what you're requesting is possible, but you should be using abstract factories through the Typed Factory Facility instead of requesting your service directly through the container.
With typed factories, all you need to do is define the factory interfaces and Windsor will take care of the implementation for you.
public interface IBusinessServiceFactory {
IBusinessService CreateBusinessService(string connString);
}
public interface IDataServiceFactory {
IDataService CreateDataService(string connString);
}
You add the facility and register your factories interface as follows:
container.AddFacility();
container.Register(Component.For().AsFactory());
container.Register(Component.For().AsFactory());
Your can now manually define how your runtime parameter gets passed down the object graph by defining a Dynamic Parameter in your BusinessServiceregistration.
container.Register(Component.For()
.LifestyleTransient()
.DynamicParameters((k, d) => {
d["dataService"] = k.Resolve.CreateDataService((string)d["connString"]);
}));
Keep in mind that the dictionary keys have to match the parameter names in the CreateBusinessService method and BusinessService constructor.
You should also make it LifestyleTransient if you intend to create a new instance each time the factory method is called. (The default is singleton)