Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the name of the name of the current Service Fabric application?

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?

like image 201
bwmartens Avatar asked Dec 20 '25 06:12

bwmartens


1 Answers

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.

like image 178
masnider Avatar answered Dec 21 '25 22:12

masnider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!