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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:22+00:00 2026-05-22T02:31:22+00:00

I have an interface IRepository and an implementation EFRepository. I use structuremap injection in

  • 0

I have an interface IRepository and an implementation EFRepository.
I use structuremap injection in order to get the repository implementation.
Right now the EFRepository has constructor with no parameter so structuremap knows to retrieve instances on EFRepository easily.

Now I need to change the repository implementation so that it will recieve in the constructor parameter that holds the unit of work.

My question in such case, how I use structuremap in order to return an instance that initialized with the unit of work?

EXAMPLE
Until today I used:

using(IUnitOfWork uow=UnitOfWork.current) {
    IRepository rep = ObjectFactory.GetInstance<IRepository<T>>();
    //repository operations that uses UnitOfWork.current that initialized above
}// here dispose of UnitOfWork.current

Now I want to use:

using(IUnitOfWork uow=new UnitOfWork()) {
    //Not sure is this is how I tell sructure map to use contractor that 
    //get IUnitOfWork)    
    IRepository rep = ObjectFactory.GetInstance<IRepository<T>>(uow);
    //repository operations that uses uow that initialized above
}// here dispose of UnitOfWork
  • 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-22T02:31:22+00:00Added an answer on May 22, 2026 at 2:31 am

    I’m assuming here that your unit of work is request-specific… So you have a service (WCF?) and each incoming request gets its own unit of work.

    Then you can configure StructureMap to define a separate unit of work per HTTP Request. If you need unit testing without HTTP Requests, you can choose for a hybrid lifecycle: per HTTP Request OR per thread. StructureMap will figure out what to do at runtime.

    ObjectFactory.Configure(x => x.For<IUnitOfWork>()
                  .HybridHttpOrThreadLocalScoped()
                  .Use<MyUnitOfWork>());
    

    Your class that needs the constructor injection simply states that it needs an IUnitOfWork:

    public MyClass(IUnitOfWork unit) { ... }
    

    This of course requires that MyClass is also managed/instantiated using StructureMap.

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

Sidebar

Related Questions

I have public interface IRepository<T> where T : EntityBase { } and its implementation,
I have an interface, called IRepository, with two implementations: SqlRepository SqlDualWriterRepository The first implementation
I have an IRepository interface that inherits from IRepository<TObject> . I also have a
I have an interface that I have defined in C++ which now needs to
I have an interface, called IRepository. One of the methods in this interface is:
I have an IRepository< T > interface with many T's and several implementations (on-demand
Here is the simple snippet: public interface IRepository<T> { T Get(int id); } public
I am using Autofac as my IoC container. I have: IRepository<> , my repository
I have the following POCO Class with its Repository Pattern Implementation. If my model
How would I wire up StructureMap with the following: public Interface IRepository<T, TIdentity>{} public

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.