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 6778367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:15:29+00:00 2026-05-26T16:15:29+00:00

I have a web that was build using ASP.NET MVC 1.0. It uses Structuremap

  • 0

I have a web that was build using ASP.NET MVC 1.0. It uses Structuremap as an IOC container.
The IOC part works nice if I register it on Application_Start like this:

ObjectFactory.Initialize(service =>
    {
        service.ForRequestedType<IOrderRepository>()
               .TheDefaultIsConcreteType<OrderRepository>()
               .CacheBy(InstanceScope.PerRequest);
    });

I have to use the same backend in a Windows Service.

The service has some timers in it that access OrderRepository simultaneously, so threading is an issue here.

My first idea is to register it in the constructor of the service like this:

public Service1()
{
    ObjectFactory.Initialize(service =>
        {
            service.ForRequestedType<IOrderRepository>()
                   .TheDefaultIsConcreteType<OrderRepository>()
                   .CacheBy(InstanceScope.PerRequest);
        });
}

Is this the right place and the right parameter for caching?

Reading the documentation of Structuremap, I think the safest way is to use the default setting for Caching:

PerRequest – The default operation. A new instance will be created for each request.

I had the impression that PerRequest meant HttpContext, but thats another entry:

HttpContext – A single instance will be created for each HttpContext. Caches the instances in the HttpContext.Items collection.

  • 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-05-26T16:15:30+00:00Added an answer on May 26, 2026 at 4:15 pm

    Per this article: http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.aspx

    The executable calls the ServiceBase derived class’s constructor the
    first time you call Start on the service
    . The OnStart command-handling
    method is called immediately after the constructor executes. The
    constructor is not executed again after the first time the service has
    been loaded, so it is necessary to separate the processing performed
    by the constructor from that performed by OnStart. Any resources that
    can be released by OnStop should be created in OnStart. Creating
    resources in the constructor prevents them from being created properly
    if the service is started again after OnStop has released the
    resources.

    It sounds like constructor is the way to go for the first time setup of structure map.

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

Sidebar

Related Questions

I have to build a registration form using asp.net mvc 3 jquery validate. That
I have an asp.net mvc app that is built to run as standard web
I have already built my web pages using jQueryMobile and ASP.NET MVC framework. Now,
I have an existing complex website built using ASP.NET MVC, including a database backend,
I have an ASP.NET MVC 3 (.NET 4) web application. This app fetches data
I have ASP.NET MVC Beta on our web server running a few apps. My
I have an asp.net mvc 2 application which works fine when run from visual
We have a web application written in ASP.NET for .NET 3.5, using standard web
I've started to wondering whether ASP.NET Webforms/MVC even have a place in the web
I have an ASP.NET MVC 3 web application. I recently installed T4MVC templates by

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.