Tag: tinyioc

EntityFramework DbContext生命周期+ Postgres:“一项操作已在进行中。”

我几天来一直在弄乱以下几天。 我有一个在Mono上运行的Nancy应用程序,带有Repository模式和UnitOfWork的EntityFramework,以及Postgres。 Nancy使用TinyIoC作为IoC容器。 我有一个Web应用程序,它在前端对请求进行排队,因此后端每次都会遇到一个请求。 一切正常。 但是,当我运行连接到同一后端的iOS应用程序并且没有将请求排队到后端时,麻烦就开始了,有时几乎同时触发请求。 随机间隔后端开始抛出此错误: 2016-09-20T13:30:16.120057436Z app[web.1]: System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. —> System.InvalidOperationException: An operation is already in progress. 2016-09-20T13:30:16.120104535Z app[web.1]: at Npgsql.NpgsqlConnector.StartUserAction (ConnectorState newState) in :0 2016-09-20T13:30:16.120113254Z app[web.1]: at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal (CommandBehavior behavior) in :0 2016-09-20T13:30:16.120119308Z app[web.1]: at Npgsql.NpgsqlCommand.ExecuteDbDataReader (CommandBehavior behavior) in […]

使用Nancy TinyIoC配置JsonNetSerializer和JsonNetBodyDeserializer

我是南希的菜鸟。 我一直在使用它作为生成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 } ); 我想使用内置的TinyIoC容器来执行此自定义,以避免inheritance链并限制Nancy.Serialization.JsonNet包中任何更改引起的潜在问题。 注意:作为临时解决方法,我利用inheritance来创建CustomJsonNetSerializer和CustomJsonNetBodyDeserializer 。 我已经尝试了几种方法来至少为JsonNetSerializer整合这种配置。 我还没有尝试使用TinyIoC配置JsonNetBodyDeserializer。 我想它会以同样的方式完成。 我尝试过的所有工作都在我的CustomNancyBootstrapper (它inheritance自DefaultNancyBootstrapper )中。 到目前为止最成功的方法:覆盖ConfigureApplicationContainer protected override void ConfigureApplicationContainer( TinyIoCContainer container ) { base.ConfigureApplicationContainer( container ); // probably don’t need both registrations, […]