Pregunta

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?

¿Fue útil?

Solución

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());
    ...
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top