Oh! Das ist ein sehr seltsames Problem. Ich werde diese beiden Typen registrieren, aber es gibt nichts, um gut zu funktionieren.Registrieren von generischen Typen in Unity config
<unity>
<typeAliases>
<typeAlias alias="IEqualityComparer`1"
type="System.Collections.Generic.IEqualityComparer`1, mscorlib" />
<typeAlias alias="singleton"
type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="EqualityComparer`1"
type="System.Collections.Generic.EqualityComparer`1, mscorlib" />
</typeAliases>
<containers>
<container>
<types>
<register type="IEqualityComparer`1"
mapTo="EqualityComparer`1">
<lifetime type="singleton" />
</register>
</types>
</container>
</containers>
</unity>
Und das ist mein Controller:
public class MyController : MyExtendedController {
private readonly IEqualityComparer<int> _fakeComparer;
public ResourcesController(IEqualityComparer<int> fakeComparer) {
_fakeComparer = fakeComparer;
}
}
Und Ausnahme wirft durch Unity wenn Controller-Lösung:
Resolution of the dependency failed, type = "MyController", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type EqualityComparer`1 cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:
Resolving MyController,(none)
Resolving parameter "fakeComparer" of constructor MyController(System.Collections.Generic.IEqualityComparer`1[[int, mscorelib]] fakeComparer)
Resolving System.Collections.Generic.EqualityComparer`1[int, mscorelib],(none) (mapped from System.Collections.Generic.IEqualityComparer`1[int, mscorelib], (none))
Irgendwelche Vorschläge geschätzt würde;)
Ich habe kein Problem mit der Konfiguration/Konfigurationen aus Config-Datei zu lesen. Ich habe Probleme beim Auflösen des registrierten Typs durch Unity. Ich habe dieses Problem mit meiner eigenen generischen Schnittstelle/Klasse getestet und das funktioniert! Aber ich kann IEqualityComparer/EqualityComparer nicht als Arbeit ansehen. – Sadegh
"System.Collections.Generic.IEqualityComparer'1, mscorlib" ist zur Vereinfachung, meine echte Alias-Definition ist etwa so: "System.Collections.Generic.IEqualityComparer'1, mscorlib, Version = 4.0.0.0, Kultur = neutral, PublicKeyToken = b77a5c561934e089 " – Sadegh
Ich sehe. Ich habe meine Antwort aktualisiert. – onof