我無法解決與統一類型。我有一個服務,需要一個Uri和布爾。RegisterType with Unity
Foo(Uri uri, bool bar)
當我嘗試解決富團結抱怨
The type Uri has multiple constructors of length 2. Unable to disambiguate
我試圖RegisterInstance但無濟於事。
我錯過了什麼?
我無法解決與統一類型。我有一個服務,需要一個Uri和布爾。RegisterType with Unity
Foo(Uri uri, bool bar)
當我嘗試解決富團結抱怨
The type Uri has multiple constructors of length 2. Unable to disambiguate
我試圖RegisterInstance但無濟於事。
我錯過了什麼?
如果你的類有多個構造函數需要兩個參數,你必須指定Unity應該使用哪一個。
如果您的構造函數接受像String,Bools或URI這樣的原始參數,您必須使用這些參數註冊映射或在解析時提供它們。
container.RegisterType<Foo>(new InjectionConstructor(new Uri("http://bla.com"), false));
或
Foo foo = container.Resolve<Foo>(new ParameterOverride("uri", new Uri("...")), new ParameterOverride("bar", false)));
應該工作。雖然我不會推薦第二種方法。 DI容器不應該以這種方式使用。
當通過Unity初始化一個wcf客戶端時,我有相同的錯誤信息。當我在我的配置中設置Unity時,解決方案是 <register xxx> <constructor></constructor> </register>
明確地調用沒有參數的構造函數。