1

当我尝试导入一些从 db 获取一些数据的服务时,dataprovider 导入始终为空(对象引用未设置为对象的实例)。我查看了聚合目录,并且包含服务的程序集似乎已正确加载。在 userControl 的 Loaded 事件中使用了对 dataprovider 的引用。

界面

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();
}

感谢帮助。问候

4

0 回答 0