So, I have an IHandler which depends on the IRepository which in turn requires a connection string. The connection string is dynamic and is passed during runtime (so it can't be read from a config file etc.)

Imagine the system creates the handler with the following code:

var handler = ObjectFactory.GetInstance<IHandler>();

This fails because the Repository dependency (the connectionString) can't be satisfied. My next idea was to use StructureMap's ExplicitArguments to supply arguments at the start of the dependency chain construction, i.e:

2 Answers
2

If you have influence on the Repository I suggest you change the constructor to require a IConnectionStringProvider and register an instance of a class implementing that interface with your object factory.