Getting the Name of a Plugin in a ServiceStack Service Class  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Getting the Name of a Plugin in a ServiceStack Service Class

Postby SBarnes » Fri May 25, 2018 6:06 pm

Hi Mike,

When extending the API and you have a ServiceStack Service Class such as the below:

Code: Select all
public class ContactSelectService : Service


Is there a way of getting the name of the actual plugin in which the class is implemented, I am asking because I want to be able to access the System Setting for the plugin but would like to avoid hard coding the value.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Getting the Name of a Plugin in a ServiceStack Service C

Postby Mike.Sheen » Fri May 25, 2018 9:39 pm

Hi Stuart,

I haven't tried this, but I think the GetAssembly method of System.Reflection.Assembly will do this - see here.

The Assembly object returned from System.Reflection.Assembly.GetAssembly(ContactSelectService) should contain the plugin name in there - as we compile assemblies from plugins using the plugin name.

EDIT: I should mention System.Reflection calls are often expensive - so I recommend doing that in the once in the plugin and storing that in a local or static variable/property and referring to that in subsequent code.

Mike
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Getting the Name of a Plugin in a ServiceStack Service C  Topic is solved

Postby SBarnes » Fri Jul 20, 2018 2:37 pm

This will actually get desired result where PluginName is declared as static in the RESTAPIPlugin class and the code is in the configure function.

Code: Select all
         System.Reflection.AssemblyName aName = new  System.Reflection.AssemblyName(System.Reflection.Assembly.GetAssembly(typeof(ContactSelectService)).FullName);
         PluginName =  aName.Name;
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to REST API

Who is online

Users browsing this forum: No registered users and 0 guests