Question

I want to disable some services programmatically. The user can specify via a configuration file if he wants to enable some part of functionality, and if not, the services should not be exposed/created. I know what services to disabled before the creation of the AppHost.

Now, I could use a RequestFilter to check every time the service is run if it is actiavted, and if not, throw an Exception. That is IMHO an unelegant solution, and the Swagger Api docs will still contain those service that should be disabled.

Any idea of how to do this the elegant way?

Was it helpful?

Solution

You can bundle services up into an IPlugin, but you will have to set the routes manually. It's how things like /metadata work.

public class MyOptionalServicesPlugin : IPlugin
{
    public void Register(IAppHost appHost)
    {
         var settings = new AppSettings();
         var enableSpecialService1 = settings.Get<bool>("enableSpecialService1", false);
         if (enableSpecialService1)
         {
             appHost.RegisterService(typeof(SpecialService1), new[] { "/special/service-1" });
         }

         ...
    }
 }

And then in your AppHost:

public void Register(Funq.Container container)
{
    Plugins.Add(new MyOptionsServicesPlugin());
    ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top