Page 1 of 1

Getting the Name of a Plugin in a ServiceStack Service Class

PostPosted: Fri May 25, 2018 6:06 pm
by SBarnes
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.

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

PostPosted: Fri May 25, 2018 9:39 pm
by Mike.Sheen
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

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

PostPosted: Fri Jul 20, 2018 2:37 pm
by SBarnes
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;