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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:41:21+00:00 2026-05-16T21:41:21+00:00

If I have the following, and I were to say ObjectFactory.GetInstance<Master>() is it possible

  • 0

If I have the following, and I were to say ObjectFactory.GetInstance<Master>() is it possible to tell StructureMap to make the I_A instance to A_User the same instance as the I_A passed to Master?

public interface I_A { }
public interface I_B { }

public class A_User {
    public A_User(I_A A) { }
}

public class Master {
    public Master(I_A _, I_B __, A_User ___) { }
}
  • 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-16T21:41:21+00:00Added an answer on May 16, 2026 at 9:41 pm

    UPDATED:
    As @Joshua Flanagan points out below, this is default SM behaviour. The following unit tests show that. The first tests uses the default behaviour. The second shows how you would get a unique instance if you wanted it:

    using System;
    using System.Collections.Generic;
    using NUnit.Framework;
    using StructureMap;
    using StructureMap.Pipeline;
    
    namespace SMTest
    {
        [TestFixture]
        public class TestSOQuestion
        {
    
            class Foo : IFoo { }
            interface IFoo { }
    
            private interface IBar {
                IFoo Foo { get; set; }
            }
            class Bar : IBar
            {
                public IFoo Foo { get; set; }
                public Bar(IFoo foo)
                {
                    Foo = foo;
                }
            }
    
            class UsesFooAndBar
            {
                public IBar Bar { get; set; }
                public IFoo Foo { get; set; }
                public UsesFooAndBar(IFoo foo, IBar bar)
                {
                    Foo = foo;
                    Bar = bar;
                }
            }
    
            [Test]
            public void TestOtherAnswer()
            {
                IContainer container = new Container(x =>
                                             {
                                                 x.For<IFoo>().Use<Foo>();
                                                 x.For<IBar>().Use<Bar>();
                                             });
                var usesFooAndBar = container.GetInstance<UsesFooAndBar>();
                Assert.AreSame(usesFooAndBar.Foo, usesFooAndBar.Bar.Foo);            
            }
    
            [Test]
            public void TestNonDefaultBehaviour()
            {
                IContainer container = new Container(x =>
                                             {
                                                 x.For<IFoo>().AlwaysUnique().Use<Foo>();
                                                 x.For<IBar>().Use<Bar>();
                                             });
                var usesFooAndBar = container.GetInstance<UsesFooAndBar>();
                Assert.AreNotSame(usesFooAndBar.Foo, usesFooAndBar.Bar.Foo); 
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following classes. In instance of BE (let's say objBE) i want to
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Let's say we have following this: <p class=first>This is paragraph 1.</p> <p class=second>This is
Let's say we have following code: struct A{ virtual ~A(){} void f(){ p =
Lets say we have following models. class User(db.Model): username=db.StringProperty() avatar=db.ReferenceProperty() class User(db.Model): username=db.StringProperty() avatar=db.StringProperty()
Say, I have following entities: @Entity public class A { @Id @GeneratedValue private Long
I'm trying to do the following say; I have a hash: {word1 => {doc1
In a web project using jsp, I have following requirement Upload a file (say
Let say I have the following data in R. training = factor(c(1,1,3,2,1,3,2,34,67,34)) test =
Let's say I have the following code: class MyClass(object): def __init__(self, param): self.param =

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.