应该在ServiceStack中添加插件的位置

时间:2013-04-06 22:31:58

标签: asp.net servicestack

如此简单但我找不到任何可以解释确切位置的信息或示例。我在这一点上猜测它应该在Configure方法中。

谢谢你, 斯蒂芬

全球

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();
    }
}

更新

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();
}

1 个答案:

答案 0 :(得分:4)

没有信息,因为Plugins中的ServiceStack可以在AppHost.Configure()方法中添加任何地方。所有ServiceStack配置和依赖项,服务,过滤器等的注册都是如此。

AppHost.Configure()方法中添加它们无关紧要,因为ServiceStack调用后它们只是已初始化

然而,它们的初始化(即IPlugin.Register()被调用)的顺序与它们的添加顺序相同。