I have a Service class that connects to a database and pulls data. A new requirement is that I connect to a second (or N) database that has the same schema, and pull the data the same way. (Each DB has different records, being setup regionally).
I'd like to reuse the Service class, and just pass in the connection string to the service. (The connection string is currently in App.config).
So, I'd like to register an instance of my service class for each database to which I'd like to connect, passing the connection string to the constructor.
Is this possible in Castle Windsor?
My best option right now is:
public class ServiceInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
foreach (var connection in Properties.Settings.Default.ServicedDBs)
{
container.Register(
Component.For<IService>()
.Named(connection)
.UsingFactoryMethod(() => new Service(
container.Resolve<ILog>(),
connection)));
}
}
}