我是南希的菜鸟.我一直在使用它作为生成REST API的框架.我熟悉Json.NET所以我一直在玩这个Nancy.Serialization.JsonNet包.
我的目标:自定义行为(即更改设置)的JsonNetSerializer和JsonNetBodyDeserializer.
具体来说,我想加入以下设置......
var settings = new JsonSerializerSettings { Formatting = Formatting.Indented };
settings.Converters.Add( new StringEnumConverter { AllowIntegerValues = false, CamelCaseText = true } );
Run Code Online (Sandbox Code Playgroud)
我想使用内置的TinyIoC容器来执行此自定义,以避免继承链并限制Nancy.Serialization.JsonNet包中任何更改引起的潜在问题.
注意:作为临时解决方法,我利用继承来创建CustomJsonNetSerializer和CustomJsonNetBodyDeserializer.
我已经尝试了几种方法来合并这种配置至少为JsonNetSerializer.我还没有尝试配置JsonNetBodyDeserializer使用TinyIoC.我想它会以同样的方式完成.我尝试过的所有工作都在我的CustomNancyBootstrapper(继承自DefaultNancyBootstrapper).
到目前为止最成功的方法:覆盖 ConfigureApplicationContainer
protected override void ConfigureApplicationContainer( TinyIoCContainer container )
{
base.ConfigureApplicationContainer( container );
// probably don't need both registrations, and I've tried only keeping one or the other
var settings = …Run Code Online (Sandbox Code Playgroud)