Page 1 of 1

How to Inject Object in Custom Route Service

PostPosted: Sun Jul 31, 2022 6:49 am
by symimake
Consider the Jiwa Example custom route plugin example.

Code: Select all
public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
   {
      public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost  AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
      {
                // How can I Inject the Manager Object in this CustomService?
           AppHost.RegisterService<CustomServices>();       
           AppHost.Routes.Add(typeof(MyDebtorContactGetRequest), "/Debtors/{DebtorID}/MyContacts", "GET", "Retrieves a list of contacts for a debtor.", "");
         AppHost.Routes.Add(typeof(MySearchRequest), "/Search/{SearchTerm}", "GET", "Performs a system wide search for a search term using a Jiwa stored procedure", "");
         AppHost.Routes.Add(typeof(MyCustomSearchRequest), "/SearchCustom/{SearchTerm}", "GET", "Performs a system wide search for a search term using a stored procedure", "");         
      }
   }


I want to inject the Manager Object in CustomService. How to do that?

Re: How to Inject Object in Custom Route Service

PostPosted: Mon Aug 01, 2022 11:22 am
by Mike.Sheen
You've posted this in the version 6 forum. Version 6 does not have a REST API. You want to post in the version 7 forum, specifically the REST API subforum.

To answer you question, inside any service class, you can use the extension method GetManager() to retrieve the Jiwa Manager object associated with the session:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.GetManager();


You can see many examples of this in the REST API plugin.