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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:44:53+00:00 2026-05-24T11:44:53+00:00

I have an interface, called IRepository, with two implementations: SqlRepository SqlDualWriterRepository The first implementation

  • 0

I have an interface, called IRepository, with two implementations:

  • SqlRepository

  • SqlDualWriterRepository

The first implementation is a regular SQL persistence implementation for objects of type T. It has a dependency on an instance of SqlConnectionStringProvider (which provides a connection string, as the name suggests and takes as constructor parameter a connection string name ).

The second is another implementation that uses internally two SQLRepository dependencies:

public class SqlDualWriterRepository<T> : IRepository<T>
{
    private readonly IRepository<T> _primaryRepository;
    private readonly IRepository<T> _secondaryRepository;

    public SqlDualWriterRepository(
        IRepository<T> primaryRepository,
        IRepository<T> secondaryRepository)
    {
        _primaryRepository = primaryRepository;
        _secondaryRepository = secondaryRepository;
    }

}

What I want to achieve is configure StructureMap so that when asking for an IRepository instance, it will:

  1. resolve IRepository to an instance of SqlDualWriterRepository
  2. resolve the two inner repositories to type SqlRepository
  3. for the two SqlRepository objects instantiated at step 2 I need to resolve the SqlConnectionStringProvider in a different way (providing different string parameters in the constructor)

I have no idea how to achieve this.
Is there a way to do it with Attributes or other types of configuration?

I’m using StructureMap 2.6.2.0.

  • 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-24T11:44:54+00:00Added an answer on May 24, 2026 at 11:44 am

    I found two solutions:

    1. Using a lambda to tell StructureMap how to build the SqlDualWriterRepository instance that will solve IRepository dependencies:

      x.For<IRepository<Type>>().Use(
              ()=> new SqlDualWriterRepository<Type>(
                  NewPrimaryRepositoryInstance<Type>(),
                  NewSecondaryRepositoryInstance<Type>()));
      
    2. Using .Ctor<>() to explicitly specify what to instantiate for each constructor dependency:

      x.For<IRepository<Type>>().Use<SqlDualWriterRepository<Type>>()
              .Ctor<IRepository<Type>>("primaryRepository").Is(NewPrimaryRepositoryInstance<Type>())
              .Ctor<IRepository<Type>>("secondaryRepository").Is(NewSecondaryRepositoryInstance<Type>());
      

    In both examples above, the NewPrimaryRepositoryInstance() and NewSecondaryRepositoryInstance() methods create the primary and secondary SqlRepositories with the appropriate SqlConnectionStringProvider configurations.

    There are probably better ways to achieve this, but these solutions do it for now.

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

Sidebar

Related Questions

I have two questions 1) my interface i have interface called IRegister and within
I'm having a small problem in Java. I have an interface called Modifiable. Objects
I have an interface, called IRepository. One of the methods in this interface is:
Let's say I have an interface called SocialNetworkService , and three implementations - TwitterService
I have an Interface called IStep that can do some computation (See Execution in
I have an interface called Dictionary which has a method insert() . This interface
I have an interface called ICommand from which various classes inherit. These classes all
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
I have a property called IsSecureConnection that is part of my object's interface. This
I have a scene, called testScene, it works like this: @interface testScene : myScene

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.