1
即使在參考the following後,我仍然很難統一註冊我的通用依賴。Unity 2.0通過配置註冊通用
我的代碼是在簡單,它沒有實現GenericRepository<T>
和如下:
public interface ISerializer<T> where T : class
{
...
}
public class WorkflowSerializer : ISerializer<XmlFormWorkflow>
{
...
}
public class WorkflowManager
{
private readonly ISerializer<XMLFormWorkflow> _serializer;
public WorkflowManager(ISerializer<XmlFormWorkflow> serializer)
{
_serializer = serializer;
}
}
我使用看起來如下conig文件:
<unity>
<alias alias="ISerializer" type="Common.ISerializer`1, Common" />
<alias alias="WorkflowSerializer" type="Common.WorkflowSerializer, Common" />
<alias alias="XMLFormWorkflow" type="Common.XMLFormWorkflow, Common" />
<container>
<register type="ISerializer[XMLFormWorkflow]" mapTo="WorkflowSerializer" />
</container>
</unity>
的錯誤,我我得到如下:
Resolution of the dependency failed, type = "Business.WorkflowManager", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Common.ISerializer`1[Common.XMLFormWorkflow], is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving parameter "serializer" of constructor Business.WorkflowManager(Common.ISerializer`1[[Common.XMLFormWorkflow, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] serializer)
Resolving Common.ISerializer`1[Common.XMLFormWorkflow],(none)
我試過包括在鋁ias
<alias alias="ISerializer" type="Common.ISerializer`1[[Common.XMLFormWorkflow, Common]], Common" />
但這似乎並不奏效。我可以在WorkflowManager
的內部強烈輸入WorkflowSerializer
,但這是我想避免的。
我只是希望我沒有忽略一些簡單的東西。 TIA