Changing Synchronous operations into Asynchronous in Business Service & Repository Layers (ASP.NET MVC 2)

寵の児 提交于 2019-12-11 07:02:29

问题


I am working on a Travel related website and here is my high level architecture:

ASP.NET MVC 2 (Presentation Layer)  
Services Layer  
Repository Layer communicating with external J2EE Services

Currently all of my layers support ONLY Synchronous communication like this:

//Pricing Controller...
public ActionResult GetRates()
{
    //Contruct Pricing Request            
    //PricingRequest request = Contruct Pricing Request...; 
    PricingResponse response = _pricingService.GetComponentPricing(request);
    //....
    //...
    return View(response);
}

//Pricing Service...
public PricingResponse GetComponentPricing(PricingRequest pricingRequest)
{
    //Do Something...
    PricingResponseDomainObject responseDomainObject = _pricingRepository.GetComponentPricing(pricingRequest.ConvertToPricingRequestDomainObject());
    //Apply Business Rules and perform some action on response
    //Convert DomainObjectResponse into ServiceObjectResponse...
    return response(PricingResponse);
}

//Pricing Repository...
public PricingResponseDomainObject GetComponentPricing(PricingRequestDomainObject pricingRequest)
{
    //Do Something...
    //Call J2EE Service and Get Response
    //Return Response
    return response(PricingResponseDomainObject);
}

Now I have a need to change my Pricing Controller to AsyncController and convert public ActionResult GetRates() into Asynchronous Action.

What changes do I need to do in my Service & Repository layers in order to support Asynchronous operations? Do I have to re-write them completely?

Edit: Need for changing Controller into Asynchronous

For a particular Search scenario, I need to call the J2EE service 1 to 5 times (independent operations), consolidate all responses into a single response and hand it over to the Controller to be able to present it to user.


回答1:


No, you likely will not have to do anything. In fact, converting them to async themselves would make your code a lot more complicated. The idea behind an async controller is that the controller action returns when it's done processing, and since those methods will still be syncronous that works out just fine. You do your work, and return when you're finished.



来源:https://stackoverflow.com/questions/5760285/changing-synchronous-operations-into-asynchronous-in-business-service-reposito

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!