Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are plug-ins supposed to be added in ServiceStack

So simple yet I can't find any info or examples that explain exacty where this should happen. I'm guessing at this point that it should be in the Configure method.

Thank you, Stephen

Global

public class AppHost : AppHostBase
{
    public AppHost() : base("Web Services", typeof(ContactsService).Assembly) { }

    public override void Configure(Container container)
    {
        //Set JSON web services to return idiomatic JSON camelCase properties
        ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

        //Show StackTrace in Web Service Exceptions
        SetConfig(new EndpointHostConfig { DebugMode = true });


        //Register any dependencies you want injected into your services
        container.Register<ICacheClient>(new MemoryCacheClient());

/*            // Redis
        container.Register<IRedisClientsManager>(c => new PooledRedisClientManager());
        container.Register<IRepository>(c => new Repository(c.Resolve<IRedisClientsManager>()));*/


        container.Register<IRepository>(new Repository());
        container.Register<IBusinessService>(new BusinessService());

        //Configure Custom User Defined REST Paths for your services
        /*ConfigureServiceRoutes();*/

        //Add a request filter to check if the user has a session initialized
        /*this.RequestFilters.Add((httpReq, httpResp, requestDto) =>
        {
            var sessionId = httpReq.GetCookieValue("user-session");
            if (sessionId == null)
            {
                httpResp.ReturnAuthRequired();
            }
        });*/


        RequestFilters.Add((httpReq, httpResp, requestDto) => new LogRequestAttribute().Execute(httpReq, httpResp, requestDto));

        Plugins.Add(new SwaggerFeature());
    }

    public static void Start()
    {
        new AppHost().Init();
    }
}

Updated

public AppHost() : base("Web Services", typeof(ContactsService).Assembly) { }

public override void Configure(Container container)
{
    ....

    ConfigurePlugins();
}

private void ConfigurePlugins()
{
    Plugins.Add(new ProtoBufFormat());
    Plugins.Add(new RequestLogsFeature());
    Plugins.Add(new SwaggerFeature());
}

private void ConfigureServiceRoutes()
{

}

public static void Start()
{
    new AppHost().Init();
}
like image 631
Stephen Patten Avatar asked Oct 04 '22 11:10

Stephen Patten


1 Answers

There is no info because Plugins in ServiceStack can be added anywhere inside your AppHost.Configure() method. This is true of all ServiceStack configuration and registration of dependencies, services, filters, etc.

It doesn't matter where in the AppHost.Configure() method they're added because they're only Initialized by ServiceStack after it has been called.

They are however initialized (i.e. IPlugin.Register() is called) in the same order that they were added.

like image 194
mythz Avatar answered Oct 13 '22 12:10

mythz