实体框架 4.1 和通用 IRepository图案和温莎
我能够注入我的 DbContext 使用
Component.For<IEFDataContextProvider>().ImplementedBy<EFDataContextProvider>().LifeStyle.PerWebRequest
.DynamicParameters((k, d) => d["context"] = new PLSS.Models.PlssContext())
并且效果很好。但是,只有当我的上下文初始值设定项不需要删除数据库时,这才有效。
DropCreateDatabaseAlways<PlssContext>
创建错误
无法删除数据库“PLSS.Models.PlssContext”,因为它当前正在使用中。
我认为这意味着这是从温莎容器中使用的。这与 PerWebRequest 的生活方式有关吗?我也尝试过 Transient 来解决同样的问题。
另外我将如何使用 xml 容器表示来创建组件。我宁愿把它放在我的 Windsor.config 中,这样我就可以在必要时更改它。
我认为这相当于我上面使用 Fluent api 所得到的结果,但我得到了一个奇怪的错误,我将在下面发布。
<component
id="IEFDataContextProvider"
service="AGRC.Common.Repositories.IEFDataContextProvider, AGRC.Common"
type="AGRC.Common.Repositories.EFDataContextProvider, AGRC.Common"
lifestyle="PerWebRequest">
<parameters>
<context>
${PlssContext}
</context>
</parameters>
</component>
<component
id="PlssContext"
type="PLSS.Models.PlssContext, PLSS.Models"
lifestyle="transient">
</component>
程序集“Microsoft.Web.Mvc,Version=2.0.0.0,Culture=neutral,PublicKeyToken=null”中类型“Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory”中的方法“GetControllerSessionBehavior”没有实现。
不确定这是怎么回事,但是......
A follow up question to Entity Framework RC1 DbContext query issue
I am able to inject my DbContext using
Component.For<IEFDataContextProvider>().ImplementedBy<EFDataContextProvider>().LifeStyle.PerWebRequest
.DynamicParameters((k, d) => d["context"] = new PLSS.Models.PlssContext())
and this is working great. However this only works if my context initializer does not need to drop the database.
DropCreateDatabaseAlways<PlssContext>
creates the error
Cannot drop database "PLSS.Models.PlssContext" because it is currently in use.
I assume that means that this is in use from the windsor container. Does this have to do with the LifeStyle being PerWebRequest? I have also tried Transient with the same issue.
Also how would I use the xml container representation to create the components. I'd rather have it in my windsor.config so I can change it if necessary.
I thought this would be equivalent to what I have above using the fluent api but i get a strange error i will post below.
<component
id="IEFDataContextProvider"
service="AGRC.Common.Repositories.IEFDataContextProvider, AGRC.Common"
type="AGRC.Common.Repositories.EFDataContextProvider, AGRC.Common"
lifestyle="PerWebRequest">
<parameters>
<context>
${PlssContext}
</context>
</parameters>
</component>
<component
id="PlssContext"
type="PLSS.Models.PlssContext, PLSS.Models"
lifestyle="transient">
</component>
Method 'GetControllerSessionBehavior' in type 'Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory' from assembly 'Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Not sure whats up with that but...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是
认为我在服务器资源管理器中有一个活动连接的典型案例。
This may have been a classic case of
Think I had an active connection in my server explorer.
您有一个针对 MVC2 编译的程序集版本,并且您正在使用 MVC3
You have a version of the assembly that's compiled against MVC2 and you're using MVC3