Using unity xml config to register an interface with nested generics

若如初见. 提交于 2019-12-03 09:43:01

Aliasing worked for me...

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <alias alias="WrappedFund" type="TestUnityIssue.Wrapper`1[[TestUnityIssue.Fund, TestUnityIssue, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], TestUnityIssue, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <namespace name="TestUnityIssue" />
    <assembly name="TestUnityIssue" />
    <container>
        <register type="IReader[Fund]" mapTo="FundReader" />
        <register type="IReader[WrappedFund]" mapTo="WrappedFundReader" />
    </container>
</unity>

these both resolved...

var fundReader = container.Resolve<IReader<Fund>>();
var wrappedReader = container.Resolve<IReader<Wrapper<Fund>>>();

and depending on your situation, you may be able to get away with less than the full AssemblyQualifiedName...

<alias alias="WrappedFund" type="TestUnityIssue.Wrapper`1[[TestUnityIssue.Fund, TestUnityIssue]], TestUnityIssue" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!