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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:14:42+00:00 2026-05-22T12:14:42+00:00

Using structuremap and c# 4.0 basically what i have is this: interface IBoard {

  • 0

Using structuremap and c# 4.0 basically what i have is this:

interface IBoard
{
    void Setup();
}

class Board : IBoard
{
    IConfig _config;

    Board(IConfig config)
    {
        _config = config;
    }

    void Setup()
    {
        //use the _config object here 
    }
}

class Game
{
    IBoard _board;

    Game(IBoard board)
    {
        _board = board;
    }
}

partial class Form1
{
    Form1()
    {
        InitializeForm();
    }

    //in here we need to do some work to setup the IConfig object 
    //via form controls
}

partial class Form2
{
    Game _game;

    Form1(Game game)
    {
        InitializeForm();
        _game = game;
    }
}

now under normal usage id just say

For<Type>().Use<Class>() 

or thereabouts for all my dependancies. However what i am after is what is the best pattern to use to set the values of the config object in form1 and then call form2 with the config values set in memory and maintained throughout the app? i thought of using a singleton however the singleton should be imuttable or at least be statically created and not accept a parameter based config… so what to do? i currently create the form1 in the Program of the winform start up via

ObjectFactory.Get<Form1>();
  • 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-22T12:14:43+00:00Added an answer on May 22, 2026 at 12:14 pm

    I don’t think that the IConfig is a good fit for creating using the container since you don’t know the parameter values until it’s time to instantiate it. I think you have to supply the configuration instance to the code that calls the container in order to fetch the form.

    You can supply arguments to the container using the With method:

    ObjectFactory.With<IConfig>(theConfig).GetInstance<Form2>();
    

    You want to minimize calls to the container, preferably just one place in you application that wire up the rest of it during bootstrapping. An alternative is to register a Func, resolve that during bootstrap and use that to create an instance of the Form2.

    Registration:

    var formFactory = config => new Form2(config);
    x.For<Func<IConfig, Form2>>().Use( () => formFactory);
    

    Usage:

    //Get the Func somehow, preferably as a ctor dependency in Form1
    var form2Creator = ... 
    var config = new Config({some parameters from Form1 here});
    var form2 = form2Creator(config);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using StructureMap for IoC, im getting Configuration from App.Config, like this: public class
I'm using StructureMap to have an instance of an interface and I wrap it
I'm using StructureMap for my DI. Imagine I have a class that takes 1
I'm using StructureMap 2.6.1 This is the code from Bootstrapper.cs: ObjectFactory.Initialize(x => x.For<IFoo>().Use<Foo>()); When
I have been using StructureMap for more than a year now. And all this
I have an asp.net mvc2 application that is using StructureMap 2.6 and NHibernate 3.x.
I'm trying to enable SqlCacheDependency through my StructureMap IoC, I'm using LinqToSql I have
I am using StructureMap on an ASP.NET MVC project. I have an object that
i've been using structuremap since a couple of months. I always use ObjectFactory.GetInstance to
Using StructureMap, is it possible to have a singleton object for each value of

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.