You can do that by adding the following method to the RequestHandlerFactory
:
public void Register(string name, Func<IRequestHandler> factory) {
var producer = Lifestyle.Transient
.CreateProducer<IRequestHandler>(factory, container);
this.producers.Add(name, producer);
}
You can use it as follows:
factory.Register("orders", () => new OrdersRequestHandler(
"my uri",
container.GetInstance<IOrderValidationService>()));
However, if that string uri
is used in more than one component, you might want to consider hiding that uri
behind an abstraction. For instance:
public interface ISomeWebServiceClientProxy {
Data LoadData();
}
class RealSomeWebServiceClientProxy : ISomeWebServiceClientProxy {
private readonly string uri;
public RealSomeWebServiceClientProxy(string uri) {
this.uri = uri;
}
public Data LoadData() {
// use uri, call web service, return data.
}
}
This way the OrdersRequestHandler
can simply take a dependency on ISomeWebServiceClientProxy
instead of the ambiguous string
:
public OrdersRequestHandler(ISomeWebServiceClientProxy proxy,
IOrderValidationService service) {
// store dependencies
}