2016-06-27 5 views
1

私はコードジェネレータによって生成された部分クラスを持っているDependenyインジェクションと部分クラス

public partial class PersonRepository: IPersonRepository 
{ 
    public string Method1(){...} 
    public string Method2(){...} 
    //... 
} 

私はこのクラスを拡張し、私はこの方法でそれ

しようとした依存性の注入に

を使用できるようにしたいと思います

public interface IPersonRepositoryExtended : IPersonRepository 
{ 
    public string Method3(){...} 
} 

public class PersonRepositoryExtended: PersonRepository, IPersonRepositoryExtended 
{ 
    public string Method3(){...} 
    //... 
} 

は、DIのために、私はPersonRepositoryExtendedIPersonRepositoryExtendedをマッピングされ、これを行う良い方法はありますか?

PersonRepositoryという部分クラスを作成する必要があります。そうすれば、インターフェイスマッピングはどのように機能しますか?

+0

必ずしも 'PersonRepositoryExtended'クラスも '拡張'インターフェースも必要ない。単に、 'public partial class PersonRepository'のところに別のファイルを追加してそこにメソッドを追加してください。 – GreatAndPowerfulOz

+0

単語_extend_を使用するときは、_derive_または_inherit_のように技術的な意味で使用しますか、むしろ部分クラスの別の部分を作成する方法を探していますか? –

答えて

2

あなたは、ほとんどがあった:あなたは

public interface IPersonRepositoryExtended : IPersonRepository 
{ 
    string Method3(); 
} 

を計画し、その後PersonRepository部分クラスを続けていたよう

は、拡張インターフェイスを作成します。以前と同じように、拡張クラスは必要ありません。

public partial class PersonRepository: IPersonRepositoryExtended 
{ 
    public string Method3(){...} 
} 

必要に応じて拡張インターフェイスを注入します。

public class SomeClass { 
    public SomeClass(IPersonRepositoryExtended dependency) { ... } 
} 

マッピングがIPersonRepositoryExtendedPersonRepositoryの間になります。

部分クラスが同じプロジェクトに属している必要があることを覚えておいてください。

関連する問題