Unity 2.0経由でクライアントをデュプレックスWCFサービス用に設定しようとしています。そのためには、私のCallbackContract - IUpdateClient
- の実装をInstanceContext
に挿入し、それを私のサービスプロキシに挿入します。この場合、のサブクラスというサブクラスに挿入します。UnityがWCF InstanceContextの実装を正しく解決できない
私が遭遇した問題は、私のユニティコンテナに格納されているサービスからアップデートにクライアントを購読するプロキシを使用しようと、私は次の例外を受信したとき、次のとおりです。
InstanceContextが に提供ChannelFactoryには、 CallbackContractType '..Services..ServiceContracts.IUpdateClient'を実装していないUserObject が含まれています。
私はそうのようなプロキシにアクセスしています:
_container.Resolve<IUpdateService>("updateServiceImpl").Subscribe();
を考えると、私のユニティ:configと
<!-- 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コンテナが01をインスタンシエートすること(config内で "instanceContext"として登録されています)、それを行う際に、 "updateClientImpl"として登録された型をインスタンス化する必要があります。実際にはIUpdateClient
を実装し、InstanceContextのコンストラクタにimplementation
パラメータとして渡します。
それにもかかわらず、私は上記のようなエラーを受け取ります。
概要(別名「the tl; dr version」): UnityコンテナがInstanceContextを解決すると、実装が正しく作成されていないようです。私はこれが設定上の誤りかどうか、またはUnityコンテナが依存型のセットをどのように解決するかを根本的に誤解しているかどうかはわかりません。これに関するガイダンスは参考になります。