Unity2.0を介してデュプレックスWCFサービス用にクライアントをセットアップしようとしています。そのためには、CallbackContract ---の実装をに挿入しますIUpdateClient
。InstanceContext
これは、サービスプロキシ(この場合は、DuplexClientBase<IUpdateService>
呼び出されたのサブクラス)に挿入されUpdateProxy
ます。
私が遭遇する問題は、Unityコンテナに格納されているプロキシを使用してクライアントをサービスからの更新にサブスクライブしようとすると、次の例外が発生することです。
ChannelFactoryに提供されるInstanceContextには、CallbackContractType'..Services..ServiceContracts.IUpdateClient'を実装しないUserObjectが含まれています。
私は次のようにプロキシにアクセスしています:
_container.Resolve<IUpdateService>("updateServiceImpl").Subscribe();
私のUnity構成を考えると:
<!-- Interface to implementation mappings -->
<register type="RepositoryInterface" mapTo="Repository" name="repositoryImpl">
<constructor>
<param name="proxy" dependencyName="proxyImpl"/>
</constructor>
</register>
<!-- Here's the bit that doesn't seem to be resolving as expected -->
<register type="UpdateClientInterface" mapTo="UpdateClient" name="updateClientImpl">
<lifetime type="singleton"/>
<constructor>
<param name="repository" dependencyName="repositoryImpl"/>
</constructor>
</register>
<register type="System.ServiceModel.InstanceContext, System.ServiceModel,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="instanceContext">
<constructor>
<param name="implementation" dependencyName="updateClientImpl"/>
</constructor>
</register>
<!-- This is the type I'm resolving with the above _container.Resolve() statement -->
<register type="UpdateServiceInterface" mapTo="UpdateService" name="updateServiceImpl">
<constructor>
<param name="callbackInstance" dependencyName="instanceContext"/>
</constructor>
</register>
<register type="ProxyInterface" mapTo="Proxy" name="proxyImpl">
<constructor>
<param name="configurationName">
<value value="ServiceEndpointFromAppConfig"/>
</param>
</constructor>
</register>
UpdateServiceクラスを解決すると、次のようになります。
public class UpdateProxy : DuplexClientBase<IUpdateService>, IUpdateService
{
public UpdateProxy(InstanceContext callbackInstance)
: base(callbackInstance) {}
public void Subscribe() {}
[...]
}
UnityコンテナはInstanceContext
(configで「instanceContext」として登録されている)をインスタンス化し、その際、「updateClientImpl」として登録されている型をインスタンス化する必要があります。これは実際には実装さIUpdateClient
implementation
れており、それをパラメータとしてInstanceContextのコンストラクタに渡します。 。
それでも、上記のようなエラーが発生します。
まとめ(別名「tl; drバージョン」): UnityコンテナがInstanceContextを解決するとき、実装が正しく作成されていないようです。これが構成のエラーなのか、それともUnityコンテナーが一連の依存型を解決する方法を根本的に誤解しているのかはわかりません。これに関するガイダンスは役に立ちます。