I will use a very simple example to describe my questions. Let's say I have a class to handle database calls
public class DatabaseAccessLayer : IDatabaseAccessLayer
{
public DatabaseAccessLayer(string uid, string password, string server)
{
// build connection object and so on
}
}
Then I have a class to use it
public class MyBusinessService : IBusinessService
{
public MyBusinessService(IDatabaseAccessLayer dal)
{
}
}
If I use Unity
as example, I would typically wire up the IoC container this way
container.RegisterType<IDatabaseAccessLayer, DatabaseAccessLayer>(new InjectionConstructor("my_uid", "my_password", "my_server"));
container.RegisterType<IBusinessService, MyBusinessService>();
It works well if I define the parameters as known values when the IoC container is set up as application starts, for example typical web application has the values in the configuration file.
However there is one requirement that I have to pass the parameters (uid, password, server) to data access layer class for every single business service call because the values could be different each time. It looks like I have no way to use IoC container in this case.
Anybody has some comments, shall I abandon IoC container in this case or there is a better way to use IoC container?