views:

204

answers:

1

I have a service proxy generated by svcutil which generated an interface(IStudentContract) and a concrete type implementing (StudentContractClient).

I'd like to have instances of StudentContractClient injected into my classes via StructureMap.

My proxy also needs to have credentials supplied as seen in this passing unit test:

        <Test()> _
    Public Sub Then_the_web_service_call_should_not_throw_an_exception()
        Dim studentServiceProxy As New StudentContractClient

        Dim credential As New NetworkCredential
        credential.Domain = ConfigurationManager.AppSettings("something")
        credential.UserName = ConfigurationManager.AppSettings("something")
        credential.Password = ConfigurationManager.AppSettings("something")
        studentServiceProxy.ClientCredentials.Windows.ClientCredential = credential

        Dim result = studentServiceProxy.GetCurrentTeachersByStudentSepid(26899)
        result.Count.ShouldEqual(4)
    End Sub

My question is what would the structuremap configuration look like to have instances of IStudentContract injected with the credentials supplied?

Thanks for any help!

A: 

From the StructureMaps' quickstart guide:

ObjectFactory.Initialize(x =>
{
     x.ForRequestedType<IRepository>()
        .TheDefault.Is.OfConcreteType<Repository>()
        .WithCtorArg("connectionString").EqualToAppSetting("CONNECTION-STRING");
});
I Clark