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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:50:15+00:00 2026-05-17T00:50:15+00:00

I have an object TestProperty which implements ITestProperty. TestProperty takes a string constructor argument.

  • 0

I have an object “TestProperty” which implements “ITestProperty”. “TestProperty” takes a string constructor argument. This is configured in StructureMap using something along the lines CtorDependency or WithCtorArg.

I want to inject the an instance of “ITestProperty” (implemented with “TestProperty”) into another class as a property. When I try to run the code I get an exception (StructureMap Error Code 205, “Missing requested Instance property”).

Here’s a simplified version that recreates the problem:

Test:

[Test]
public void Can_resolve_the_correct_property()
{
    ObjectFactory.Initialize( x => x.AddRegistry( new TestRegistry() ) );

    var instance = ObjectFactory.GetInstance<TestController>();
}

Registry Setup:

public class TestRegistry : Registry
{
    public TestRegistry()
    {
        ForRequestedType<ITestProperty>().AddInstances( 
            i => i.OfConcreteType<TestProperty>().WithName( "Test" )
                .CtorDependency<string>( "arg" ).Is( "abc" )
        );

        //ForConcreteType<TestProperty>().Configure
            .CtorDependency<string>( "arg" ).Is( "abc" );

        ForConcreteType<TestController>().Configure
            .SetterDependency( p => p.Property ).Is<TestProperty>()
            .WithName( "Test" );
    }
}

Test Objects:

public interface ITestProperty { }

public class TestProperty : ITestProperty
{
    private readonly string arg;

    public TestProperty( string arg )
    {
        this.arg = arg;
    }

    public string Arg { get { return arg; } }
}

public class TestController
{
    public ITestProperty Property { get; set; }
}

When we go to initialize the “TestController” object above the exception is thrown. Is it possible to do this with StructureMap? Assuming that it is possible, what do I need to do to get it working?

Thanks in advance.

  • 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-17T00:50:16+00:00Added an answer on May 17, 2026 at 12:50 am

    There are several ways to do this, as Josh mentioned if the named instance is important then you want this in your registry:

    ForRequestedType<ITestProperty>().AddInstances(i => 
        i.OfConcreteType<TestProperty>().WithName("Test")
            .WithCtorArg("arg").EqualTo("abc"));
    
    ForConcreteType<TestController>().Configure
        .SetterDependency(p => p.Property).Is(c => c
            .GetInstance<ITestProperty>("Test"));
    

    Otherwise, you can do this:

    ForRequestedType<ITestProperty>().TheDefault.Is
        .OfConcreteType<TestProperty>()
        .WithCtorArg("arg").EqualTo("abc");
    
    ForConcreteType<TestController>().Configure
        .SetterDependency(p => p.Property).IsTheDefault();
    

    Also, this is old StructureMap syntax, you might want to update to the latest version. Here is the new syntax:

    For<ITestProperty>().Add<TestProperty>().Named("Test")
        .Ctor<string>("arg").Is("abc");
    
    ForConcreteType<TestController>().Configure
        .Setter(p => p.Property).Is(c => c
            .GetInstance<ITestProperty>("Test"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have object called Foo. Right now it implements IFoo which has a lot
Lets say I have object Tom which has class Person. Class Person String Name
I have object A which contains multiple instances of object B, which in turn
I have shared object A.so which statically links to libssl.a & another shared object
I have this object: stdClass Object ( [daily_inventoryID] => 1 [inventory_timestamp] => 2012-06-08 14:35:42
We have Object and ValueType .... And String .... String is derived from object,
I have object Country, which has Areas. Areas has Provinces. Provinces has Cities, and
I have following code: public abstract class TestProperty { public abstract Object PropertyValue {
I have a class: public class MyClass<T> { public string TestProperty { get; set;
I have object (div-box), and it's draggable (I'm using jQuery). How I can get

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.