c# – 如何在Repository中注入EntityFramework Core DbContext
大多数在线示例处理asp.net并将其DbContext注册为其启动服务注册表的一部分.
我尝试像这样注册我的DbContext builder.RegisterType<MyContext>() .As<MyContext>() .InstancePerLifetimeScope(); builder.RegisterType<DealRepository>() .Keyed<IRepository<Deal>>(FiberModule.Key_DoNotSerialize) .As<IRepository<Deal>>() .SingleInstance(); builder.RegisterType<CardsDialog>() .As<IDialog<object>>() .InstancePerDependency(); 但是我收到了这个错误
它更复杂,因为实际的MessageController.cs在Post上创建了一个新的范围 using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container,activity)) { var dialog = scope.Resolve<IDialog<object>>(); await Conversation.SendAsync(activity,() => dialog); } 如何进行注册? 编辑: builder.RegisterType<DealJob>() .AsSelf() .SingleInstance();
我此时应手动解析新的DbContext吗?或许我应该改变我的回购生命周期? Edit2:看起来即使删除整个Quartz作业注册,我仍然会收到此错误. 解决方法
我对这个问题错了,它不是IoC和DbContext问题.好像它是在.NET平台本身
https://github.com/dotnet/corefx/issues/9846#issuecomment-274707732 添加重定向就可以了 <dependentAssembly> <assemblyIdentity name="System.ComponentModel.TypeConverter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.0.0" /> </dependentAssembly> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |