简体   繁体   中英

Entity Framework 4.1 and the Generic IRepository<T> Pattern and Windsor

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...

This may have been a classic case of 在此处输入图片说明

Think I had an active connection in my server explorer.

您有针对MVC2编译的程序集版本,并且您正在使用MVC3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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