【问题标题】:Inject WCF proxy with credentials using StructureMap使用 StructureMap 注入带有凭据的 WCF 代理
【发布时间】:2010-12-01 07:21:41
【问题描述】:

我有一个由 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 实例注入了所提供的凭据,结构映射配置会是什么样子?

感谢您的帮助!

【问题讨论】:

    标签: wcf dependency-injection


    【解决方案1】:

    来自StructureMaps' quickstart guide

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多