locked
Beginning Web API project design question RRS feed

  • Question

  • User-969659544 posted

    For a few years I have developed and maintained a large ASP.NET web forms application with 3 layers: Presentation, Business logic (BLL) and Data access (DAL).  

    I am looking at creating a Web API to compliment this application and allow functionality from mobile devices.  I have been following the articles and tutorials on this site and others.

    Most of the CRUD is already done by the existing BLL and DAL.  Can I just make calls from the various Controllers to methods in the BLL similar to the web form application?  The BLL takes care of getting the values or recordsets from the DAL and returns the correct object or data to the Controller.

    I have been reading about Entity and Dependency Injection.  All new to me.  I am not opposed to learning what is needed, but it seems like all the data work has already been done in the web forms application.  I could reuse code and modify slightly to work in the Web API.

    Is this the wrong approach?  At a high level am I missing something that will be a big road block to developing the Web API down the road?

    Thx

    Wednesday, April 27, 2016 4:43 PM

Answers

  • User-286291038 posted

    Hi ITPartTimer,

    It seems your application has been designed well and is in a good state to migrate to MVC and to use Web API.

    In controller, in any case, we do not  write any business logic inside it. The business models take care of implementing the business logic. So you should be able to leverage your existing BLL and DAL to perform the business functions and data access. The controllers can just orchestrate this process. You may just need to create some view models to pass the required information that needs to be displayed to the view in case you implement MVC. Web API does not need a view, but similar to MVC, the Web API controller can also leverage your existing BLL and DAL architecture.

    Using dependency injection could make your application more elegant since you can initiate your BLL objects as a constructor to your controller and use dependency injection for instantiating these objects.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 27, 2016 7:53 PM

All replies

  • User-286291038 posted

    Hi ITPartTimer,

    It seems your application has been designed well and is in a good state to migrate to MVC and to use Web API.

    In controller, in any case, we do not  write any business logic inside it. The business models take care of implementing the business logic. So you should be able to leverage your existing BLL and DAL to perform the business functions and data access. The controllers can just orchestrate this process. You may just need to create some view models to pass the required information that needs to be displayed to the view in case you implement MVC. Web API does not need a view, but similar to MVC, the Web API controller can also leverage your existing BLL and DAL architecture.

    Using dependency injection could make your application more elegant since you can initiate your BLL objects as a constructor to your controller and use dependency injection for instantiating these objects.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 27, 2016 7:53 PM
  • User36583972 posted

    Hi ITPartTimer,

    Can I just make calls from the various Controllers to methods in the BLL similar to the web form application?  

    Yes, you can call from the various Controllers to methods in the BLL. First, you should add your Business logic (BLL) and Data access (DAL) in your Web API.
    The following tutorial introduces Web API business layer, you can refer.
    The Web API business layer anti-pattern:
    http://www.bizcoder.com/the-web-api-business-layer-anti-pattern

    Is this the wrong approach?  At a high level am I missing something that will be a big road block to developing the Web API down the road?

    You can learn about Web API in the below link. If you have any question about Web API, you can get help and support from everyone in here.
    http://www.asp.net/web-api

    Best Regards,

    Yohann Lu

    Thursday, April 28, 2016 1:42 AM
  • User-969659544 posted

    Nataraj / Yohann - 

    Thanks for the info.  I have added my BLL and DAL to the project.  Calling the BLL methods from the Controller and keeping it simple.  I want to leverage what I know, but keep the code organized and testable as the project grows.

    Yohann - 

    The bizcoder link isn't working.  I have gone to this site in the past, but today it's not reachable.  I'll try again later.

    Sunday, May 1, 2016 3:05 PM