简体   繁体   English

为什么ServiceStack.Text自定义反序列化设置不适用?

[英]Why do ServiceStack.Text custom deserialization settings not apply?

I use ServiceStack.Text with ServiceStack (the web service framework). 我将ServiceStack.Text与ServiceStack(Web服务框架)一起使用。

I'm trying to add a custom serialization route for a specific type in AppHost.Configure() . 我正在尝试在AppHost.Configure()为特定类型添加自定义序列化路由。 However, the settings do not apply/are ignored. 但是,设置不适用/被忽略。

public AppHost : AppHostBase 
{
    ...

    public override void Configure(Container container)
    {
        //Register custom serialization routine
        ServiceStack.Text.JsConfig<CultureInfo>.SerializeFn = r => r.TwoLetterISOLanguageName;
        ServiceStack.Text.JsConfig<CultureInfo>.DeSerializeFn = r => return new CultureInfo(r);    
    }
}

ServiceStack.Text is caching internally very heavily to achieve fast performance. ServiceStack.Text在内部进行非常大的缓存以实现快速性能。 ServiceStack is already starting the cache creation process before AppHost.Configure() is called. AppHost.Configure()之前,ServiceStack已经开始了缓存创建过程。

So to resolve this issue, you need to register your settings before AppHost.Init() is called. 因此,要解决此问题,您需要在AppHost.Init()之前注册您的设置。

Of course this isn't required for all settings in ServiceStack.Text - it's only required for the settings which will be cached before AppHost.Configure() is called. 当然,ServiceStack.Text中的所有设置都AppHost.Configure() - 只有在AppHost.Configure()之前缓存的设置才需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM