I'm new to dependency injection, I'm wondering how you would handle the following scenario. We have something like the following:
public class DatabaseContext
{
public string ConnectionString {get;}
}
public interface IDataAccess
{
string GetString(int id);
}
public class DataAccessImpl : IDataAccess
{
private DatabaseContext _context;
public DataAccessImpl(DatabaseContext context)
{
this._context=context;
}
public string GetString(int id)
{
return "some data";
}
}
For web applications each request could build up a different DatabaseContext to point to a different database. For windows forms we could change the current DatabaseContext. How does a di framework handle a dependency that can change? Such that when i request a IDataAccess it always has the appropriate/current DatabaseContext.