使用Unity容器

时间:2018-01-16 02:10:55

标签: c# dependency-injection inversion-of-control unity-container

我已经注册了一个服务,它需要接收一个字符串,其值在运行时在其构造函数中确定:

public BingSpeechRecognitionService(
    IBingAuthentificationService authentificationService, string runtimePlatform)

所以我尝试使用 Resolve 方法在Unity容器中手动解析此参数,如下所示:

Container.Resolve(typeof(string), new ParameterOverride("runtimePlatform", 
    Device.RuntimePlatform));

我的问题是 Resolve 方法会引发以下异常

  

InvalidOperationException:无法构造String类型。您   必须配置容器以提供此值。

我该怎么做才能解析字符串参数?

0 个答案:

没有答案
相关问题