2017-09-18 6 views
0

私はこの問題を数時間で解決しようとしています。私はインターネットを検索し、多くのStackoverflowの質問を見ましたが、誰も私を助けることができませんでした。StructureMap複数の種類の汎用タイプを開く


パイプラインを構築しています。基本的なconecptは以下の通りです:

  • PipelineStore(シングルトン) - 一方のエンティティあたりPipeline(アカウント、連絡先、...)
  • PipelineStep - パイプライン[TEntity](トランジェント)登録されているすべてのPipeline
  • が含まれています[TOperation、TInteractor、TEntity(トランジェント) - ジェネリック型を表すPipeline

[]当たり多くの工程。


StructureMapを使用してパイプラインとPipelineStepを作成します。それから私はIPipelineFactoryが注入され、以下のようにそれを使用し得る

For<IPipelineFactory>().CreateFactory(); 
For(typeof(IPipeline<>)) 
    .Use(typeof(Pipeline<>)) 
    .Transient(); 

私はレジストリにそれを登録し

IPipeline<TEntity> CreatePipeline<TEntity>() TEntity : EntityDTO, new(); 

:だから私は、単一の機能を有するIPipelineFactoryと呼ばれる自動車工場を作成しました

public IPipeline<TEntity> NewPipeline<TEntity>() 
    where TEntity : EntityDTO, new() 
{ 
    var pipeline = _pipelineFactory.CreatePipeline<TEntity>(); 
    _pipelines.Add(pipeline); 
    return pipeline; 
} 

これは素晴らしいですが、私がパイプラインで同じことをしようとするとESTEPそれは失敗します。

public interface IPipelineStepFactory 
{ 
    IPipelineStep<TOperation, TInteractor, TEntity> CreatePipelineStep<TOperation, TInteractor, TEntity>() 
     where TOperation : IOperation<TInteractor, TEntity> 
     where TInteractor : IInteractor<TEntity> 
     where TEntity : EntityDTO, new(); 
} 

および登録:

For<IPipelineStepFactory>().CreateFactory(); 
For(typeof(IPipelineStep<,,>)) 
    .Use(typeof(PipelineStep<,,>)); 

用法:

public IAddPipeline<TEntity> Pipe<TOperation, TInteractor>() 
    where TOperation : IOperation<TInteractor, TEntity> 
    where TInteractor : IInteractor<TEntity> 
{ 
    var step = PipelineStepFactory.CreatePipelineStep<TOperation, TInteractor, TEntity>(); 
    RegisteredSteps.Add(step); 
    return this; 
} 

私はそれが実行時に次の例外をスローするコードをテストしてみてください:

No default Instance is registered and cannot be automatically determined for type 'IPipelineStep<TestOperation, ITestInteractor, TestEntity>' 

There is no configuration specified for IPipelineStep<TestOperation, ITestInteractor, TestEntity> 

私はおそらく、複数の型引数を持つオープンジェネリック型のサポートがないと考えています。この問題を解決するためのワークラウンドがある場合は、教えてください。御時間ありがとうございます!

答えて

0

私はそれを自分で考え出しました。問題は、PipelineStepに多少異なるジェネリックタイプの制約があり、問題が発生していたことです。私は

public class PipelineStep<TOperation, TInteractor, TEntity> : PipelineStepBase, IPipelineStep<TOperation, TInteractor, TEntity> 
     where TOperation : IOperation<TInteractor, TEntity> 
     where TInteractor : IInteractor<TEntity> 
     where TEntity : EntityDTO 

、今それが働いているに

public class PipelineStep<TOperation, TInteractor, TEntity> : PipelineStepBase, IPipelineStep<TOperation, TInteractor, TEntity> 
    where TOperation : IOperation<TInteractor, TEntity>, IOperation<IInteractor<EntityDTO>, EntityDTO> 
    where TInteractor : IInteractor<TEntity>, IInteractor<EntityDTO> 
    where TEntity : EntityDTO 

を変更しました!

関連する問題