ASP.NET MVC 3, RavenDB, & Autofac Issue Plus 2 Other Autofac Questions

前端 未结 2 1291
-上瘾入骨i
-上瘾入骨i 2021-01-05 05:08

NOTE: There are 3 questions in here and I did not make separate questions since they are all somewhat related to the same code.

I have the following

相关标签:
2条回答
  • 2021-01-05 05:43

    I'm guessing you want something like:

    builder.Register(c => c.Resolve<DocumentStore>().OpenSession()).InstancePerLifetimeScope();
    

    "The default ASP.NET and WCF integrations are set up so that InstancePerLifetimeScope() will attach a component to the current web request or service method call." - Autofac: InstanceScope

    Basically, in a web app, InstancePerLifetimeScope handles the one per HTTP context aspect, and also disposes any types that implement IDisposable.

    0 讨论(0)
  • 2021-01-05 05:57

    There was also the issue that OpenSession returns a IDocumentSession instead of a DocumentSession. Changing my class to look for a IDocumentSession along with doing what Jim suggested worked, thanks.

    0 讨论(0)
提交回复
热议问题