Click here to Skip to main content
15,562,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to implement a Rest service inside my application, which already has different layers (Business Logic Layer, Data Access Layer and Data Model which contains all my entities). I'm gonna using IIS (locally) and Visual Studio.

I created a new project of type ASP.NET -> WEB API.
I have to call the methods of the Business Logic Layer from the controller, so I defined a variable of the Business Logic Type: I'm gonna use it to call the methods.

How should I refer to the resources which REST is gonna use? Should I refer to my Data Model Layer or should I create new classes inside the Models folder in my Rest project (one for each entity)?

What I have tried:

I created an ASP.NET projct of type Web API (empty).
I added an interface which contains all the methods of my Business logic layer.
I created a new controller which implements the interface; inside it, I defined a _businessLogicVariable of the Business Logic class.

I call the methods of the Business Logic by using this variable.
When a method returns void I use [HttpGet], elsewhere I use [HttpPost], e.g I wrote the following to return a User, by posting a username and a password:

[HttpPost]        
        public User Login(string username, string password)         {
            return _businessLogic.Login(username, password);
        }


User is a new class I created inside the folder Models in my Rest project:
Should I set the
[Route("api/User")] 
in the WebApiConfig instead? I mean, should I do that in order to call it from the dataModelLibrary (the external project/layer in the same solution)?
Posted
Updated 19-Nov-20 4:14am
v2

1 solution

 
Share this answer
 
Comments
xhon 19-Nov-20 9:16am    
thanks a lot for your answer. I edited my question (now I am more focused on how to manage the resources in my rest service project implementation)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900