2015-06-01 2 views
0

У меня есть интерфейс и реализацию следующим образом:Вложенные Дженерики Регистрация с помощью файла конфигурации Unity

public interface IDataProcessor<T, U> 
    { 
     U Process(T data); 
    } 

public sealed class CustomDataProc: IDataProcessor<List<string>, Dictionary<string, Dictionary<string, List<string>>>> 
    { 
      ... 
    } 

Когда я зарегистрировать эту реализацию с использованием традиционного стиля, как показано ниже, все решает в порядке и в порядке.

container.RegisterType<IDataProcessor<List<string>, Dictionary<string, Dictionary<string, List<string>>>>, CustomDataProc>(); 

Теперь, при использовании XML, как показано ниже регистраций (т.е. позвонить в container.LoadConfiguration (раздел)) проходит, но при разрешении корневого объекта он терпит неудачу.

<typeAliases> 
    <typeAlias alias ="Dictionary" type ="System.Collections.Generic.Dictionary`2, mscorlib" /> 
    <typeAlias alias ="List" type ="System.Collections.Generic.List`1, mscorlib" /> 
... 
</typeAliases> 
<container> 
<register type="IDataProcessor[List[string], Dictionary[string, Dictionary[string, List[string]]]]" mapTo="CustomDataProc"/> 
... 
</container> 

Это с ошибкой

"Resolution of the dependency failed, type = ... 
while resolving.\r\nException is: InvalidOperationException - The current type, 
IDataProcessor`2[System.Collections.Generic.List`1[System.String],System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.String]]]], 
is an interface and cannot be constructed. Are you missing a type mapping? 

Я думаю, что это что-то делать с вложенными дженериков, так как один из других моих отображения типа с одним родовым работал отлично.

Любая идея, как это можно решить успешно?

Благодаря

ответ

1

Это работало для меня ...

<typeAliases> 
    <typeAlias alias="IDataProcessor" type="StackOverflow_30583255.IDataProcessor`2, StackOverflow_30583255" /> 
    <typeAlias alias="CustomDataProc" type="StackOverflow_30583255.CustomDataProc, StackOverflow_30583255" /> 
</typeAliases> 
<container> 
    <register type="IDataProcessor`2[List[string],Dictionary[string,Dictionary[string,List[string]]]]" mapTo="CustomDataProc" /> 
</container> 
+0

Благодаря выглядит в регистрации и вам нужен задний тик ('). Работает сейчас! –

Смежные вопросы