Note that there are some explanatory texts on larger screens.

plurals
  1. PORegistration in IoC container after initial configuration
    primarykey
    data
    text
    <p>I have a scenario where I would like to register a single instance of a component in the container, but unfortunately it cannot be created at application startup. This component could only be instantiated passing some objects which are only available a bit later in application lifecycle (they are not other IoC registered services, however) <em>[see note below]</em>.</p> <ul> <li>Is registering a component in a IoC container <strong>after</strong> the initial configuration (run in app startup) a bad practice? </li> <li>How to accomplish it without directly referencing the container? Should I abstract a registration service?</li> <li>There is a better approach to support the scenario?</li> </ul> <hr> <p><em>NOTE about the actual scenario</em><br> The component I would like to put in the container is initialized with a particular instance of an UI control (it is basically an adapter), hence I have to manually create the component instance and register it in the container.<br> I would have done this at application startup, but unfortunately I don't have the UI control instance available yet (nor can I create it by myself).<br> Even at later time, I cannot reach the UI control instance from the surface of other components without knowing their concrete class.<br> For this reason I thought I could put the responsibility for the adapter registration into the class which owns the UI control.</p> <p>My initial scenario:</p> <pre><code>public interface IDockManager { ... } public class AcmeDockManagerAdapter : IDockManager { public AcmeDockManager(DockControl control) { ... } ... } public class ShellViewModel { ... } public class ShellView : Window { internal DockControl theDockControl; } public class AnotherViewModel { AnotherViewModel(IDockManager dockManager) { ... } } </code></pre> <p>The solution I'm unconfortable with:</p> <pre><code>public class ShellView : Window { internal DockControl theDockControl; public ShellView () { InitializeComponents(); var dockManager = new AcmeDockManagerAdapter(theDockControl); //registration in the container } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload