示例:我有一个国家目录存储在另一个数据库中,我需要将它用作某些 ContentParts 中的属性。我正在尝试在不干扰 Orchard 布线的情况下建立连接。
public class MoviePart : ContentPart<MoviePartRecord>
{
public IEnumerable<CountryRecord> Countries
{
get
{
return Record.Countries.Select(r => r.CountryRecord);
}
}
}
CountryRecords 和 MovieParts 之间的关系将在 Orchard 数据库中,但 CountryRecord 数据在另一个数据库中。我只需要读取访问权限,但我不知道哪个以及如何覆盖处理程序以使用其他源。
我是否需要创建一个 ContentHandler 并覆盖所有方法,并创建另一个使用新存储库和外部源的 StorageFilter?我如何将新的 repo 注入到处理程序中?
public class CountryPartHandler : ContentHandler
{
public CountryPartHandler(IRepository<CountryPartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
protected override void Loading(LoadContentContext context)
{
base.Loading(context);
}
}
更新:
在这个Using External Data with Orchard(大约第 25 分钟)视频中,他似乎正在用这段代码做我需要的事情:
public ProductPartHandler(IRepository<ProductPartRecord> repository, Work<IProductService> productServiceWork)
{
Filters.Add(StorageFilter.For(repository));
OnActivated<ProductPart>((context, part) => {
part.ProductField.Loader(() => productServiceWork.Value.GetProduct(part.Id));
});
}
但是在我的代码中它找不到“加载器”功能,即使我也有视频中的所有引用,所以也许 ProductField 是一个自定义类型?