-
Notifications
You must be signed in to change notification settings - Fork 14
Tutorial 04 09 Add Controller Class
You're almost there, only two more steps to go, the next of which is to actually expose your Traditional Bridge routines as endpoints of your web service.
There are several ways that you might choose to do this, depending on what your routines do, and how they may or may not relate to existing functionality exposed by existing controllers in your service.
For example, if your service is exposing OData endpoints for Orders, and your Traditional Bridge routines also expose functionality related to Orders, you may choose to expose them via custom endpoint methods on your existing OrdersController class.
But it may be that your Traditional Bridge functions are not related to other controllers in your service. In that case, it probably makes sense to simply add a new custom controller class. That's the approach we'll take here.
-
In
Solution Explorer
, right-click on theServices.Controllers
class and selectAdd > Class
. -
Name the new class source file
TraditionalBridgeController.dbl
and click theAdd
button. -
Copy and paste the following code into the new class, replacing the default code:
;;***************************************************************************** ;; ;; Title: TraditionalBridgeController.dbl ;; ;; Description: WebAPI controller to expose example Traditional Bridge Routines ;; ;;***************************************************************************** import Microsoft.AspNetCore.Authorization import Microsoft.AspNetCore.Mvc import Microsoft.Extensions.Configuration import Microsoft.Extensions.Options import Newtonsoft.Json import System import System.Collections.Generic import System.Linq import System.Text import System.Threading.Tasks import Services.Controllers import Services.Models namespace Services.Controllers {Authorize} {Route("TraditionalBridge")} public partial class TraditionalBridgeController extends ControllerBase ;; Services provided via dependency injection private _TraditionalBridgeService, @TraditionalBridgeService public method TraditionalBridgeController aTraditionalBridgeService, @TraditionalBridgeService proc _TraditionalBridgeService = aTraditionalBridgeService endmethod endclass endnamespace
As you can see, the new class inherits from a base class named ControllerBase (actually Microsoft.AspNetCore.Mvc.ControllerBase), which in a nutshell means that it is an MVC Controller (previously referred to as a WebAPI controller).
Again, the dependency injection pattern is being used, this time to get hold of an instance of a class named TraditionalBridgeService
. Does that sound familiar? It should, it's the class that you wrote in the previous module of this tutorial, the one that exposes "wrapper" methods for your Traditional Bridge routines. Yes, it's all starting to come together!
Next topic: Configure Traditional Bridge Environment
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information