清风:EFContextProvider /微风控制器和服务层 [英] Breeze: EFContextProvider/Breeze Controller and Service Layer

查看:145
本文介绍了清风:EFContextProvider /微风控制器和服务层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用微风,我想知道人们会如何去与处理的东西,如电子邮件通知,审计日志,业务验证(即客户必须存在)等。

When using Breeze, I was wondering how one would go about integrating it with a service layer which handles things such as email notifications, audit logs, business validations (ie Customer must exist) etc..

例如,考虑以下情形:

public class SalesAppRepository
{
    private readonly EFContextProvider<SalesAppContext> _contextProvider;

    public SalesAppRepository(EFContextProvider<SalesAppContext> contextProvider)
    {
        _contextProvider = contextProvider;
    }

    private SalesAppContext Context { get { return _contextProvider.Context; } }

    public string MetaData
    {
        get { return _contextProvider.Metadata(); }
    }

    public SaveResult SaveChanges(JObject saveBundle)
    {
        return _contextProvider.SaveChanges(saveBundle);
    }

    public IQueryable<Customer> Customers
    {
        get { return Context.Customers; }
    }

    public IQueryable<Order> Orders
    {
        get { return Context.Orders; }
    }

   /* Other entities */
}

[BreezeController]
public class BreezeController : ApiController
{
    private readonly SalesAppRepository _repository; 

    public BreezeController(SalesAppRepository repository)
    {
        _repository = repository;
    }

    [HttpGet]
    public string Metadata()
    {
        return _repository.MetaData;
    }

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return _repository.SaveChanges(saveBundle);
    }

    [HttpGet]
    public IQueryable<Customer> Customers()
    {
        return _repository.Customers;
    }

    [HttpGet]
    public IQueryable<Order> Orders()
    {
        return _repository.Orders;
    }

    /* Other entities */
}

我有当正在创建的实体,修改等。订单在创建时,如其他一些业务逻辑;客户必须能够下订单(bool值 canOrder ),并必须存在,也是一种电子邮件必须发送和审计日志必须更新,以显示新创建的订单。这只是其中的一个方案中,有通常会坐在我的服务层的其他情况,但我不知道我会如何与微风结合呢?

I have some other business logic when entities are being created, modified etc.. such as when an Order is created; the Customer must be able to place an order (bool value canOrder) and must exist, also an email must be sent and an audit log must be updated to show the newly created order. This is just one scenario, there are other situations which would usually sit in my service layer, but I'm not sure how I would incorporate this with breeze?

我明白我可以覆盖的SaveChanges 方法 SalesAppContext 来生成审计日志,但对于其他情况?我不知道,我会把这在问候上面?

I understand I can override the SaveChanges method on the SalesAppContext to generate the audit log, but what about the other situations? I'm not sure where I would put this in regards to above?

我似乎已经找到了,虽然,哈克的方式来解决这个问题,我已经上传,我希望能帮助别人,或加以改进一个要点:的 https://gist.github.com/CallumVass/8300400

I seem to have found an, albeit, hacky way to get around this problem, I have uploaded a gist which I hope could help someone or be improved upon: https://gist.github.com/CallumVass/8300400

推荐答案

我已经纳入我的业务逻辑在beforeSaveEntities(..)方法:
http://www.breezejs.com/documentation/efcontextprovider

i've incorporated my business logic in the beforeSaveEntities(..) Method: http://www.breezejs.com/documentation/efcontextprovider

这篇关于清风:EFContextProvider /微风控制器和服务层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆