使用实体框架和postsharp创建需要缓存的对象模型的选项是什么



我正在使用一个对性能要求很高的互联网应用程序,这意味着良好的缓存功能对我们的成功至关重要。

该解决方案使用实体框架代码优先用于数据库访问,Postsharp用于缓存。目前,模型如下所示。

public class Article 
{
    private readonly IProducerOperator _producerOperator;
    public Article(IProducerOperator operator)
    { _producerOperator = operator; }
    public int Id { get; set; }
    ...
    public int ProducerId { get; set; }
    public Producer Producer { 
        get { return _producerOperator.GetProducer(ProducerId); }
    }
}

操作类如下所示。

public class ArticleOperations : IArticleOperations
{
    private readonly IDataContext _context;
    public ArticleOperations(IDataContext context)
    { _context = context; }
    [Cache]
    public Article GetArticle(int id)
    {
        var article = _context.Article.Find(id);
        return article;
    }
}
public class ProducerOperations : IProducerOperations
{
    private readonly IDataContext _context;
    public ProducerOperations(IDataContext context)
    { _context = context; }
    [Cache]
    public Producer GetProducer(int id)
    {
        var producer = _context.Producer.Find(id);
        return producer;
    }
}

我不喜欢在业务对象中具有依赖性,但它的论点是从缓存中进行懒惰加载。。。最多。这个解决方案还意味着,生产者只需要缓存一次。。。在CCD_ 1处。通常我甚至不会考虑在那里有依赖关系。对象应该是POCO,仅此而已。我真的需要一些新的投入。我该怎么做呢?这是最好的方法吗?

我们还需要解决相反的问题,即,从缓存的生产者那里,我们应该能够检索到它的所有文章。

首先,我想说的是,实际上有一些(一个?)解决方案首先使用实体框架代码,并结合使用postsharp的缓存。IdealaBlades首先发布了Devforce代码,实际上正是这样做的。这种框架实际上解决了所有问题,我们可以按照应该使用的方式使用实体框架,并与缓存相结合。

但这并没有成为本案的解决方案。我们完全分离了关注点,这意味着只有业务对象关注点才包含数据。操作类负责填充业务对象。

最新更新