Reputation: 179
Is there a way to get the metadata of a website built using Servicestack framework programmatically? We're looking to build an app that will look for a Servicestack website hosted on 2 different environments and find out if there are any differences between them. Here are the metadata details that we expect to read from the Servicestack website in the app programmatically:
Upvotes: 2
Views: 295
Reputation: 143319
Yes you can access most of ServiceStack's metadata from Metadata
property in your AppHost which returns the ServiceMetadata class. When outside your AppHost you can access it from the HostContext.Metadata
singleton.
A lot of the information can be accessed from OperationsMap, e.g:
var allServices = HostContext.Metadata.OperationsMap.Values.ToList();
Which will return a List<Operation>
containing most of the metadata about a Service, e.g:
Routes
propertyRequestType
and ResponseType
returns the Request DTO Type and the known Response DTO TypeAll Request DTOs are DTOs/complex types. The way to access information about each Type is to use C# Reflection methods. You can use the Type.GetSerializableProperties()
extension method to get the serializable PropertyInfo[]
of a Type
.
Note you can also query a lot of this metadata in real-time using the Metadata Debug Template, enabled when you register the TemplatePagesFeature
plugin:
Plugins.Add(new TemplatePagesFeature {
EnableDebugTemplate = true, // viewable by Admin users
//EnableDebugTemplateToAll = true // viewable by all users
})
Where you can query ServiceStack metadata of your Services in real-time using ServiceStack Templates:
Upvotes: 1