Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:03:01+00:00 2026-06-05T09:03:01+00:00

I’m using Simple Injector for an IOC in an MVC 3 web application. I

  • 0

I’m using Simple Injector for an IOC in an MVC 3 web application. I am using RavenDB for the data storage. There are several considerations on using RavenDB in an mvc 3 application. I’ve searched some on how to wire-up an IoC to use RavenDB but haven’t found out how to wire-up simple injector to use RavenDB. Can anyone explain how to wire-up simple injector to use RavenDB in an MVC 3 web app?

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:03:03+00:00Added an answer on June 5, 2026 at 9:03 am

    According to the RavenDb tutorial, your application needs exactly oneIDocumentStore instance (per database I assume). A IDocumentStore is thread-safe. It produces IDocumentSession instances and they represent a unit of work in RavenDB, and those are not thread-safe. You should therefore not share sessions between threads.

    How to set up your container for use with RavenDb mainly depends on the application design. The question is: what do you want to inject in to consumers? The IDocumentStore, or the IDocumentSession?

    When you go with the IDocumentStore, your registration could look like this:

    // Composition Root
    IDocumentStore store = new DocumentStore
    {
        ConnectionStringName = "http://localhost:8080"
     };
    
    store.Initialize();
    
    container.RegisterSingle<IDocumentStore>(store);
    

    A consumer might look like this:

    public class ProcessLocationCommandHandler
        : ICommandHandler<ProcessLocationCommand>
    {
        private readonly IDocumentStore store;
    
        public ProcessLocationCommandHandler(IDocumentStore store)
        {
            this.store = store;
        }
    
        public void Handle(ProcessLocationCommand command)
        {
            using (var session = this.store.OpenSession())
            {
                session.Store(command.Location);
    
                session.SaveChanges();
            }            
        }
    }
    

    Because the IDocumentStore is injected, consumers are themselves responsible for managing the session: creation, saving, and disposing. This is very convenient for small applications, or for instance when hiding the RavenDb database behind a repository, where you call session.SaveChanges() inside the repository.Save(entity) method.

    However, I found this type of use of a unit of work to be problematic for larger applications. So what you can do instead, is injecting the IDocumentSession into consumers. In that case your registration could look like this:

    IDocumentStore store = new DocumentStore
    {
        ConnectionStringName = "http://localhost:8080"
    };
    
    store.Initialize();
    
    // Register the IDocumentSession per web request
    // (will automatically be disposed when the request ends).
    container.RegisterPerWebRequest<IDocumentSession>(
        () => store.OpenSession());
    

    Note that you need the Simple Injector ASP.NET Integration NuGet package (or include the SimpleInjector.Integration.Web.dll to your project, which is included in the default download) to be able to use the RegisterPerWebRequest extension method.

    The question now becomes, where to call session.SaveChanges()?

    There is a question about registering unit of works per web request, which also addresses the question about SaveChanges. Please take a good look at this answer: One DbContext per web request…why?. When you replace the words DbContext with IDocumentSession and DbContextFactory with IDocumentStore, you will be able read it in the context of RavenDb. Note that perhaps the notion of business transactions or transactions in general are not that important when working with RavenDb, but I honestly don’t know. This is something you will have to find out for yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.