我有一个由svcutil生成的服务代理,它生成一个接口(IStudentContract)和一个实现的具体类型(StudentContractClient)。
我想通过StructureMap将StudentContractClient的实例注入我的类中。
我的代理还需要提供凭据,如此传递单元测试所示:
<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
我的问题是,如果使用提供的凭据注入IStudentContract实例,结构图配置会是什么样的?
感谢您的帮助!
答案 0 :(得分:1)
来自StructureMaps' quickstart guide:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IRepository>()
.TheDefault.Is.OfConcreteType<Repository>()
.WithCtorArg("connectionString").EqualToAppSetting("CONNECTION-STRING");
});