Application wide PropertyBag

Is there something like a PropertyBag available that can store application wide values? Something akin to IRequest.Items but across the entire appHost (at HostContext/AppHost level?) rather than per-request?

I’ve had a search and can’t see anything that fits the bill.

We have a number of plugins and we don’t want to have hard dependencies against them but in some instances there is the need to fetch a primitive-type in PluginA that was set by PluginB.

The value is not essential to the functionality of PluginA but if it’s there then it can be used. I was thinking that if there is something like IRequest.Items then PluginA and PluginB would only need to share a common PropertyBag key rather than anything more (such as a DTO type).

If such a thing doesn’t exist what would be the best way to store values that can be shared across plugins? ICacheClient?

You can register your own shared type in IOC container in AppHost.Configure and get access to it in Plugins using IAppHost interface. Example: register it in AppHost.cs

public override void Configure(Container container)
   container.Register<SharedType> (new SharedType ());

get it in plugin:

public class CustomPlugin : IPlugin
     public void Register (IAppHost appHost)
          Container container = appHost.GetContainer();
          SharedType obj = container.Resolve<SharedType>();

If you just want to share State registered in your Plugin to make it available to all your Services then you can register an object instance in the IOC as @xplicit has shown.

But if you just want to be able access a different plugin properties you can just get the registered plugin directly from the AppHost.Plugins collection, e.g from within Plugin B:

var pluginA = appHost.GetPlugin<PluginA>();
if (pluginA.HasFeature) {

You can also access plugins anywhere from in or outside of ServiceStack via the HostContext, e.g:

var pluginA = HostContext.GetPlugin<PluginA>();

Two other options:

a) Service.LocalCache

b) If you want it at the AppHost level … why not just add it at the AppHost level?

class BigBag : Dictionary<string,object> {}

class FerminAppHost : AppSelfHostBase {
    public BigBag BigBag { get; set; }

... elsewhere
var foo = (AppHost.Instance as FerminAppHost).BigBag["foo"];
1 Like

We wanted to avoid taking any type dependencies between plugins hence a more indirect approach.

As it turns out, we wanted to pass the discovery registration identifier to the IAppSettings provider but we already have a unique service identifier in the AppHost IP:Port/path so we’re just using that instead.

A nice update for the ConsulAppSettings is coming soon to have fidelity over configuration of a single service > versioned named services > and global. All without touching your running services.

Use what’s OOTB whenever possible :wink: