簡體   English   中英

團結與通用

[英]Unity and Generics

如何在Unity中注冊和解析通用對象/接口? 我試圖遠離配置文件。

我正在尋找類似的東西

IEnterpriseClient<IInterface1>解析為EnterpriseClient<IInterface1>

班級簽名是

class EnterpriseClient<T> : IEnterpriseClient<T> where T : class

謝謝!

這幾乎就是你的想法:

container.RegisterType<IEnterpriseClient<IInterface1>, EnterpriseClient<IInterface1>>( ... );

如果您只想要特定的封閉通用注冊,那就是這樣。 對於開放式通用(不僅僅是IInterface1),您可以:

container.RegisterType(typeof(IEnterpriseClient<>), typeof(EnterpriseClient<>), ... );

你提到你試過這個 - 什么不起作用?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM