Is it possible to get the name of the Service Fabric application where my code is running?
For example, my ApplicationParameters file has this:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/mytestapp" xmlns="http://schemas.microsoft.com/2011/01/fabric">
I want to retrieve "mytestapp" and use it in my code, but I haven't found anything that would let me do that. Any ideas?
ApplicationName is present as a string (unfortunately not a URI) as a property on the CodePackageActivationContext.
// System.Fabric.CodePackageActivationContext
public string ApplicationName
{
get;
internal set;
}
CodePackageActivationContext is present on the ServiceContext that every service is passed in its constructor. Example from stateful services.
public StatefulService(StatefulServiceContext serviceContext)
: this(serviceContext, new ReliableStateManager(serviceContext, null))
{
}
If your service is a guest or a container or something that doesn't use the ReliableServices API, then passing the name explicitly as a config setting is probably your best bet.