I have the following type which I need to be instantiated by StructureMap:
public class AWebService : IAWebService
{
private readonly string _applicationId;
private readonly string _username;
private readonly string _password;
public AWebService(string applicationId, string username, string password)
{
_applicationId = applicationId;
_username = username;
_password = password;
}
}
The problem is that this constructor takes 3 parameters. I’ve seen examples how to provide StructureMap with one parameter (e.g. Passing constructor arguments when using StructureMap) but I’m not sure what I need to do to pass 3 in.
Is it simply a case of:
For<IAWebService>().Use<AWebService>()
.Ctor<string>("applicationId").Is(GetIDFromConfig())
.Ctor<string>("username").Is(GetUsernameFromConfig())
.Ctor<string>("password").Is(GetPasswordFromConfig());
or do I have to configure it differently?
Have you tried the code in your question, it looks correct.
Register your type with structuremap and set the string constructor parameters
Then you can get your service with the parameters set.