データベースからデータを取得するサービスをインポートしようとすると、データプロバイダーのインポートは常に null (オブジェクト参照がオブジェクトのインスタンスに設定されていません) になります。Aggregatecatalog を調べたところ、Service を含む Assembly が正しく読み込まれているようです。dataprovider への参照は、userControl の Loaded イベントで使用されます。
インターフェース
public interface IGetSampleData
{
IEnumerable<SampleDataValueObject> GetAllSampleData();
}
サービス
[Export(typeof(IGetSampleData))]
public class SampleDataService : IGetSampleData
{
private ISampleData dax = new SampleDataRepository();
public IEnumerable<SampleDataItem> GetAllSampleData()
{
throw new NotImplementedException();
}
}
ビューモデル
[Export]
public class SampleDataViewModel : BaseViewModel
{
[Import(typeof(IGetSampleData))]
public IGetSampleData DataProvider { get; set; }
//in Loaded event dataprovider is null
var src = this.DataProvider.GetAllSampleData();
}
手伝ってくれてありがとう。よろしく