Change Behaviour of webhooks

Discussions relating to the REST API of Jiwa 7.

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Mon Feb 01, 2021 5:34 pm

SBarnes wrote:How can you reference WebHookEvents and Webhook from another plugin?


WebHookEvents is a static property of the RESTAPIPlugin class - so you add a plugin reference and then you should have access to that List.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Feb 01, 2021 5:45 pm

No actually that doesn't work it becomes an issue of scope that I figured out if you don't rename the classes in the second plugin to say MyBusinessLogicPlugin and MyRestAPIPlugin the editor seems to get confused, I tried partial on the classes but that didn't resolve it either as I suspect for that to work you'd need partial classes in both plugins but renaming the classes definitely resolves it and doesn't cause any side effects as Jiwa is looking for interface implementations so the class name doesn't really matter.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Mon Feb 01, 2021 6:05 pm

Ahhh... yes I have a memory now of coming across that issue when working on the caching.

I got around it by registering in the Funq container of the REST APLI the class I wanted to access, and in the other plugin Resolving it.

So, in the REST API plugin in the Configure method of the RESTAPIPlugin class you register a type and the instance to associate with that type - so if you wanted to access the RESTAPIPlugin instance itself:

Code: Select all
Container.Register<RESTAPIPlugin>(this);


What that's doing is associating the type RESTAPIPlugin with an instance of itself (this).

Then in your plugin, you can retrieve that via:

Code: Select all
RESTAPIPlugin restAPIPlugin = Container.TryResolve<RESTAPIPlugin>();


This needs to also go into the Configure method as the Container is passed as a parameter to that.

If you want something more flexible (say you want to access it via another plugin which DOES NOT implement the IJiwaRESTAPIPlugin interface, then you could create your own container, shove that into the ObjectDictionary of the Manager class - so then you can access the container from anywhere which has access to the Manager (pretty much everywhere).

ObjectDictionary is just a System.Collections.Generic.Dictionary - so just add it like:

Code: Select all
Manager.ObjectDictionary.Add("Container", Funq.Container); // Funq.Container requires a reference to ServiceStack.dll


Then from anywhere you should be able to access the container to register types and resolve instances from the type.

Hope that helps!
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Behaviour of webhooks

Postby SBarnes » Tue Feb 02, 2021 8:23 am

Thanks Mike

Ok I am assuming for the Business Logic Plugin you would need to do the following:

Code: Select all
Manager.ObjectDictionary.Add("BusinessLogicPlugin", this);


to make

Code: Select all
BusinessLogicPlugin.Webhook(JiwaBusinessLogic.Manager, "", "");


work also?

Just an idea would it be possible add a property to the manager called RESTAPI so that you could have

Code: Select all
manager.RESTAPI.RESTAPIPlugin


and
Code: Select all
manager.RESTAPI.BusinessLogicPlugin


permanently available going forward otherwise every time you upgrade a system you have to edit the REST API plugin with the instructions you gave?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Tue Feb 02, 2021 10:54 am

SBarnes wrote:Thanks Mike

Ok I am assuming for the Business Logic Plugin you would need to do the following:

Code: Select all
Manager.ObjectDictionary.Add("BusinessLogicPlugin", this);


to make

Code: Select all
BusinessLogicPlugin.Webhook(JiwaBusinessLogic.Manager, "", "");


work also?


I've not tried it, but yes I believe that would work.

SBarnes wrote:Just an idea would it be possible add a property to the manager called RESTAPI so that you could have

Code: Select all
manager.RESTAPI.RESTAPIPlugin


and
Code: Select all
manager.RESTAPI.BusinessLogicPlugin


permanently available going forward otherwise every time you upgrade a system you have to edit the REST API plugin with the instructions you gave?


Because there can be multiple instances (like you can have multiple plugins implementing IJiwaRESTAPIPlugin), I'm currently not able to see how that would work...
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Behaviour of webhooks

Postby SBarnes » Tue Feb 02, 2021 11:21 am

I meant it would only reference back to the main REST API plugin by the way I also found an issue that setting the execution order fixes but if you have the line


Code: Select all
JiwaFinancials.Jiwa.JiwaServiceModel.RESTAPIPlugin.WebHookEvents.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.WebHookEvent { Name = "salesorder.processed", Description = "Occurs when a sales order is processed" });


in a plugin where it's name would put it before the REST API such as it starts with Attkey then you get null reference exception that stops the service starting it doesn't matter that the REST API plugin is listed under the plugin references as I believe this doesn't change the load order.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Previous

Return to REST API

Who is online

Users browsing this forum: No registered users and 5 guests