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

  • Home
  • SEARCH
  • 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 9049763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:28:59+00:00 2026-06-16T12:28:59+00:00

I use structuremap library and following code to config DI in a WinForm App:

  • 0

I use structuremap library and following code to config DI in a WinForm App:

 private static void InitializeStructureMap()
        {
            ObjectFactory.Initialize(x =>
            {
                x.For<IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use
                    <CouponContext>();


                x.For<ICouponService>().Use<EFCouponService>();
                x.For<IUserService>().Use<EFUserService>();
            });
        }

also i use following code to GetInstance of Classes in a form:

private IUnitOfWork uow;
private IUserService userService;

public LoginForm()
{
    InitializeComponent();

    uow = ObjectFactory.GetInstance<IUnitOfWork>();
    userService = ObjectFactory.GetInstance<IUserService>();
}

How is the life cycle of UnitOfWork in my App?

  • 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-16T12:29:00+00:00Added an answer on June 16, 2026 at 12:29 pm

    By default it’s per request, but you can configure it

    x.For<IUnitOfWork>()
     .LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton))
    

    From documentation:

    PerRequest - The default operation.  A new instance will be created for each request.
    Singleton - A single instance will be shared across all requests
    ThreadLocal - A single instance will be created for each requesting thread.  Caches the instances with ThreadLocalStorage.
    HttpContext - A single instance will be created for each HttpContext.  Caches the instances in the HttpContext.Items collection.
    HttpSession - A single instance will be created for each HttpSession.  Caches the instances in the HttpContext.Session collection.  Use with caution.
    Hybrid - Uses HttpContext storage if it exists, otherwise uses ThreadLocal storage.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using StructureMap 2.6.1 This is the code from Bootstrapper.cs: ObjectFactory.Initialize(x => x.For<IFoo>().Use<Foo>()); When
I need to initialize StructureMap.ObjectFactory in ASP.NET MVC 3 application. ObjectFactory.Initialize(x => x.For<Db>().HttpContextScoped().Use<Db>()); Do
i've been using structuremap since a couple of months. I always use ObjectFactory.GetInstance to
I want to use StructureMap ObjectFactory to handle the instantiation of my classes used
I have this registration in StructureMap ObjectFactory.Initialize(x => { x.For<IPageModel>().UseSpecial(y => y.ConstructedBy( r =>
This is my StructureMap bootstrapping: ObjectFactory.Initialize(factory => { //Business Conversation is per session factory.ForRequestedType<IConversation>().
I'm adapting some code originally written for Windsor to use StructureMap. In the Windsor
I see a lot of examples of how to use StructureMap in a asp.net
I am trying to use StructureMap to register some types that implement a generic
I'm trying to use StructureMap 2.6.1 to register all my repositories at once using

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.