Skip to content

Tutorial 04 09 Add Controller Class

Steve Ives edited this page May 26, 2020 · 22 revisions

Harmony Core Logo

Exposing Endpoints for Traditional Bridge Routines

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.

Add a Custom Controller Class

  1. In Solution Explorer, right-click on the Services.Controllers class and select Add > Class.

  2. Name the new class source file TraditionalBridgeController.dbl and click the Add button.

  3. 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


Clone this wiki locally