This tutorial describes what a configurable provider service (microservice) is and how to create a service from the Alkami template. We will do the following:
Build and configure the template service.
Test and debug the example service implementation.
Add new settings and a new contract method that will fetch and use those settings.
Create a new feature for this example and equip it with new request and response objects.
Create object models to store the request and response data with data validations that confirm our request data is valid.
Implement the new feature logic.
Use the Micros Service Tester to test.
Provider-based Services
Developers use provider-based services to define configurable settings for use in the service implementation.
Use Alkami’s Admin Portal to manage these settings.
To do this, go to Setup > Integration Settings and click Providers.
The Alkami Provider Service Template
The SDK template creates a structured Visual Studio solution that contains all the projects and implementation details to run the service. The service can be built and run out-of-the-box and contains an easy-to-follow implementation of a single public method.
The example code is commented and lays down a request and response pattern to follow when adding additional contract methods.
Install the Template
Run the following command:
choco install Alkami.SDK.Templates -y
Create the Service
Alkami’s SDK template creates a structured Visual Studio solution that contains all the projects and implementation required to run a service with a single public contract method.
The example code adheres to Alkami’s preferred request and response pattern so you can take advantage of the Validation framework.
Open Visual Studio and search alkami to filter for Alkami templates.
Note: Your version of Visual Studio might look different than the following screenshots.
Select the Alkami Provider Service template and click Next.
Uncheck ‘Place solution and project in same directory’ option if it is selected.
Do not select any options and click Create.
Build the Solution
By default the Service.Host will be the Startup Project.
a.If it is not, right-click the project and select Set as StartUp Project. Build the solution to restore the NuGet packages and create a Debug build of the service.
Configure the Service
To insert the service configuration into the DeveloperDynamic database, locate the insert_provider_setting.sql in the Service.Host project
and open it using your SQL engine of choice.
Run the script.
In Server Name, type . then click Connect.
Run and Test the Service
Open the Service project.
Click to set a break point on the first line of of the ServiceImp.GetSettingsAsync() method within the ServiceImp.cs class.
Run (F5) the solution within Visual Studio (Administrator). This opens a cmd.exe window that encapsulates the Host project to make debugging easier.
See Topshelf’s documentation page for more information about this strategy.
A console window opens and runs the service so you can see what is happening in the subscription service. The GetSettingsAsync() public method has a solid red break point.
Open the Windows Services to see a list of Alkami services including the Alkami.Services.SubscriptionHost.
After installation, from the Windows Start Menu, search for and open MicroServiceTester.
The left margin lists the available services.
Double-click a service to view the available contract methods.
Select a contract method.
For our new service, we will select GetSettings and then click Send Message.
The tester sends a request and the code execution should pause on the break point we set in the GetSettingsAsync() implementation method.
Unit Tests
The template creates a test project and a single test method CanGetSettings() that will create an instance of the distributed service. It then uses the DistributedServices.cs
class in the ServiceHost project to call the GetSettingsAsync() method and assert that the two default settings are fetched properly.
Place a break point in the CanGetSettings() test method to debug the service using a unit test.
Press F10 to step through the code execution.
First Service Loan Decision Feature
The remainder of this tutorial will use an invented feature to guide the developer through the process of extending the template service.
The example feature is a Loan Decision engine and will generate a loan approval and a loan amount based on some information provided by the member.
The client request will contain a data model that describes the Application Detail submitted by a member.
The response will contain a similar model that describes the Loan Detail returned by our decision logic.
We will define new settings, create a request and a response object, create data validations where necessary and add a new GetLoanDecisionAsync() method so that other services
and widgets can use the new First Service feature.
Define the new settings
All settings are defined within the service itself. The admin portal has the privilege of overriding the default settings by persisting the values to Alkami’s database.
These database values will be used as overrides of the DefaultSettings we’ll be creating in this tutorial.
We’ll duplicate a lot of the existing pattern in order to add two new template settings. The areas that should be added to your classes are highlighted in yellow.
Add the new setting name(s)
One of the features in the FirstService service will determine if a member is eligible for a loan. The loan amount should not exceed a maximum amount and must be greater than a
minimum amount. These two values are great candidates to be converted to configurable settings.
Add the default setting values
In this case, we’ll set the default values for the max and min to 95000 and 5000 respectively.
Add new descriptors
Descriptors are required and further define the settings when viewing them in the Admin Portal. It’s important to make these meaningful and as descriptive as possible.
Create new setting validations
The last step is to add validations for these two new settings. These validations are executed when an admin user attempts to update these values using Alkami’s Admin Portal UI.
For this example, we’ll make sure to fail any values that cannot be parsed into an integer.
Read the new setting
The existing template settings already show the proper pattern for reading settings, we’ll do the same but instead of assigning the string value we’ll parse it into a
usable integer type.
We’ll create two local variables so that we can use the settings outside of the disposable DataScope() and then parse the settings into the proper primitive type and assign them
to the local variables.
Adding New Contract Methods
In the previous section we added new settings and updated the existing GetSettingsAsync() method to read in the new values. This section will focus on adding a new public contract method to the service that contains some business logic that will use the new settings we added before.
Much of this implementation is new code, we’ve provided the classes in full so that users can easily copy and paste where necessary. Also, the source code has been provided at the top of this page.
Defining New Request and Response Types
Requests and responses should be more than a list of properties. The service architecture gives the developer full freedom to define complex object types and for that reason we’ll be creating new data objects that will be members of the request and response objects.
Create new data objects
The request and response types will have data object members to customize the type of information we want to receive and return. We’ll be taking a member’s application details as part of the request and responding with the loan details once we’ve ran through our logic.
Add two new classes to the Data project, named LoanDecisionDetail.cs that will be used to store the data from our decisioning logic and MemberApplicationDetail.cs
that will contain the information we will use within the decision process.
LoanDecisionDetail.cs
MemberApplicationDetail.cs
Create the new request and responses classes
In the Contracts project, add these classes below to the Requests and Responses folders respectively
GetLoanDecisionRequest.cs
LoanDecisionResponse.cs
Creating an Entity Validator
The new request and its members should have validations to make sure the service performs as efficiently as possible.
We will create two new entity validators, one for the GetLoanDecisionRequest.cs and another for the MemberApplicationDetail.cs
which is an object member of the GetLoanDecisionRequest.cs. We want to make sure both of these types are formatted correctly
before we send the request to the implementation method.
Add the following classes to the Validations project
GetLoanDecisionRequestValidator.cs
Updating the Service Contract
The IFirstServiceContract is the interface that defines which implementation methods are available to be publicly called.
We want our new method to be publicly accessible so we’ll need to add that method stub.
This is the full IFirstServiceContract.cs with the new GetLoanDecisionAsync() method stubbed out.
IFirstServiceContract.cs
Updating the Service Client
The service client is the proxy between the caller and the host service.
We’ll need to stub out a proxy method similar to the one that was added by the template.
Add the new GetLoanDecisionAsync() method stub so that your class looks like the one below
FirstServiceServiceClient.cs
Updating ServiceImp
ServiceImp.cs
Updating the Service Host
The final place we need to stub out our new contract method is within the DistributedService itself. This is also where we want to add our two validatiors we created earlier.
Add a new method stub for GetLoanDecisionAsync() and add two new entity validators so that your class now looks like the one below
DistributedService.cs
Testing the New Loan Decision Feature
We have all the implementation details in place! Now it’s time to test our new contract method using the Micro Service Tester.
Start the service in Visual Studio and select the new GetLoanDecision contract method.
Open the ApplicationDetail property and populate it’s members with some test data.
Click OK and then click Send Message
The response will have our new decision details! This data was approved for a $15000 loan, congrats!
Identifying Additional Settings
It’s always good to look at your implementation and determine if there are additional variables that can be converted to configurable settings.
I’ve purposefully left some “magic numbers” in the example ServiceImp.LoanDecision.cs partial class and I’ve circled them below in the screen shot.
These are great candidates for configurable settings and can be added right along with the min and max settings.