Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get an instance in StructureMap Registy constructor?
    primarykey
    data
    text
    <p>How can I get an instance of some type (registered in a different Registry) inside StructureMap Registy constructor? I want to use such a code:</p> <pre><code> public RepositoriesRegistry() { IApplicationSettings lApplicationSettings = ObjectFactory.GetInstance&lt;IApplicationSettings&gt;(); Debug.Assert(lApplicationSettings != null); const string cSupportedDevicesConnectionString = "metadata=res://*/Models.SupportedDevices.Database.SupportedDevicesModel.csdl|res://*/Models.SupportedDevices.Database.SupportedDevicesModel.ssdl|res://*/Models.SupportedDevices.Database.SupportedDevicesModel.msl;provider=System.Data.SqlClient;provider connection string=\"{0}\""; string lSupportedDevicesConnectionString = string.Format(cSupportedDevicesConnectionString, lDatabaseConnectionString); SupportedDevicesEntities lSupportedDevicesEntities = new SupportedDevicesEntities(lSupportedDevicesConnectionString); ForRequestedType&lt;SupportedDevicesEntities&gt;().TheDefault.IsThis( lSupportedDevicesEntities); ForRequestedType&lt;ISupportedDevicesRepository&gt;().TheDefault.IsThis( new SupportedDevicesRepository(lSupportedDevicesEntities)); } </code></pre> <p>IApplicationSettings is an interface to application settings. The concrete type implementing this interface (currently ConfigFileApplicationSettings class) is registered in another registry like this:</p> <pre><code> public ApplicationServicesRegistry() { ForRequestedType&lt;IApplicationSettings&gt;().TheDefault.IsThis( new ConfigFileApplicationSettings()); } </code></pre> <p>And both registries are registered in the Bootstrapper:</p> <pre><code> #region IBootstrapper Members public void BootstrapStructureMap() { ObjectFactory.Initialize(InitalizeStructureMapContainer); } #endregion #region Private properties private static bool HasStarted { get; set; } #endregion #region Private methods private void InitalizeStructureMapContainer(IInitializationExpression x) { x.IgnoreStructureMapConfig = true; x.AddRegistry&lt;ViewModelRegistry&gt;(); x.AddRegistry&lt;ApplicationServicesRegistry&gt;(); x.AddRegistry&lt;RepositoriesRegistry&gt;(); x.AddRegistry&lt;DataOperationsRegistry&gt;(); } #endregion </code></pre> <p>When I try to get an instance of IApplicationRegisty in registry constructor I've got an error (of course). I don't completly understand how to use StructureMap the right way. May be I should do the thing some different way. But anyway can I get an instance of some type early registered in an Registry constructor?</p>
    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.
    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