2009-07-15 77 views
1

我有一個由svcutil生成的服務代理,它生成了一個接口(IStudentContract)和一個實現(StudentContractClient)的具體類型。注入WCF代理憑證使用StructureMap

我想通過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 

我的問題是會是什麼structuremap配置模樣有IStudentContract的情況下,與提供的憑據注入?

感謝您的幫助!

回答

1

StructureMaps' quickstart guide

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