本文介绍了像void main()这样的服务层编排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告:这可能是一个愚蠢的问题,如果您有心脏问题,应立即离开。

HI,

很抱歉烦恼的问题,但我没有别的办法...

我知道每一层都有自己的工作,PP层为用户,服务层为外观,业务层为验证和业务逻辑,CRUD操作的数据层和一般持久性职责。

但是在某些时候你必须指定一个层作为主层(void main()?)..

应该是哪一层?服务?

让我们从DoFactory.com分析这个代码的和平来发生在这个代码中。<$ la $ ="x-c#"> ///< summary>
///请求客户数据。
///< / summary>
///< param name =" request">客户请求消息。< / param>
///< returns>客户回复消息。< / returns>
public CustomerResponse GetCustomers(CustomerRequest request)
{
CustomerResponse response = new CustomerResponse();
response.CorrelationId = request.RequestId;

//验证客户端标记,访问令牌和用户凭证
if(!ValidRequest(request,response,Validate.All))
返回响应;

CustomerCriteria criteria = request.Criteria as CustomerCriteria;
string sort = criteria.SortExpression;

if(request.LoadOptions.Contains(" Customers"))
{
IEnumerable< Customer>顾客;
if(!criteria.IncludeOrderStatistics)
{
//没有订单信息的简单客户列表
customers = customerDao.GetCustomers(criteria.SortExpression);
}
else if(sort.IndexOf(" NumOrders")> = 0 || sort.IndexOf(" LastOrderDate")> = 0)
{
//排序顺序由Order Dao
IList< Customer>处理。 list = customerDao.GetCustomers();
customers = orderDao.GetOrderStatistics(list,sort);
}
其他
{
//排序顺序由客户Dao处理,但也需要订单统计
IList< Customer> list = customerDao.GetCustomers(sort);
customers = orderDao.GetOrderStatistics(list);
}
response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c))。ToList();
}

if(request.LoadOptions.Contains(" Customer"))
{
Customer customer = customerDao.GetCustomer(criteria.CustomerId);
if(request.LoadOptions.Contains(" Orders"))
customer.Orders = orderDao.GetOrders(customer.CustomerId);

response.Customer = Mapper.ToDataTransferObject(customer);
}

返回回复;
}


如你所见,这是我无法消化它的代码的和平。
这里的服务层就像是编写流程的void main()..


我http://www.zapacila.com

解决方案


WARNING: This may be a stupid question, if you have heart problems you should leave immediately.

HI,

Sorry for being annoying with the questions, but i have no other way...

I know that each layer has it`s own work, PP layer for user, service layer as a facade, business layer for validation and business logic, data layer for CRUD actions and general persistence responsibilities..

But at some point you have to assign one layer to be the master (the void main() ?) ..

Which layer should that be? Service?

Let's analyze this peace of code from DoFactory.com

        /// <summary>
        /// Request customer data.
        /// </summary>
        /// <param name="request">Customer request message.</param>
        /// <returns>Customer response message.</returns>
        public CustomerResponse GetCustomers(CustomerRequest request)
        {
            CustomerResponse response = new CustomerResponse();
            response.CorrelationId = request.RequestId;

            // Validate client tag, access token, and user credentials
            if (!ValidRequest(request, response, Validate.All))
                return response;

            CustomerCriteria criteria = request.Criteria as CustomerCriteria;
            string sort = criteria.SortExpression;

            if (request.LoadOptions.Contains("Customers"))
            {
                IEnumerable<Customer> customers;
                if (!criteria.IncludeOrderStatistics)
                {
                    // Simple customer list without order information
                    customers = customerDao.GetCustomers(criteria.SortExpression);
                }
                else if (sort.IndexOf("NumOrders") >= 0 || sort.IndexOf("LastOrderDate") >= 0)
                {
                    // Sort order is handled by the Order Dao
                    IList<Customer> list = customerDao.GetCustomers();
                    customers = orderDao.GetOrderStatistics(list, sort);
                }
                else
                {
                    // Sort order is handled by the Customer Dao, but alse need order statistics
                    IList<Customer> list = customerDao.GetCustomers(sort);
                    customers = orderDao.GetOrderStatistics(list);
                }
                response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c)).ToList();
            }

            if (request.LoadOptions.Contains("Customer"))
            {
                Customer customer = customerDao.GetCustomer(criteria.CustomerId);
                if (request.LoadOptions.Contains("Orders"))
                    customer.Orders = orderDao.GetOrders(customer.CustomerId);

                response.Customer = Mapper.ToDataTransferObject(customer);
            }

            return response;
        }

As you see this is the peace of code that i have trouble digesting it. 
the service layer here is like the void main() orchestrating the flow..


Me http://www.zapacila.com

解决方案


这篇关于像void main()这样的服务层编排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:58