Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Factory using StructureMap
    primarykey
    data
    text
    <p>Posted this on the structuremap group as well. We just started using structuremap last week, and are really digging it.</p> <hr> <p>I'm sure I'm missing something simple. </p> <p>I am trying to mimic the following code, using SM within my factory. I'm ok with having the container dependency in the factory class. The consensus in this thread seemed to be that this was the right approach: <a href="http://www.codeplex.com/unity/Thread/View.aspx?ThreadId=29697" rel="nofollow noreferrer">http://www.codeplex.com/unity/Thread/View.aspx?ThreadId=29697</a>. If there is a better way, I'm open to hearing other ways of accomplishing this. </p> <p>Basically my factory's Create method will take in an enum value (it might be an actual type, but either way it's not something controlled by the container), and should return the right instance. Note that the return types WILL be managed by SM. I don't want to put all the depenencies in the Ctor of the factory, since there could be many (!). </p> <pre><code>public class PreSaveActionFactory : IPreSaveActionFactory { public IPreSaveAction Create(MyEnumType enumType) { IPreSaveAction action; switch (enumType) { case MyEnumType.Value1: //imagine this has 3 Ctor arguments action = new Value1PreSaveAction(); break; case MyEnumType.Value2: //and imagine this has 4 completely different Ctor arguments action = new Value2PreSaveAction(); break; default: throw new NotSupportedException(); } return action; } } </code></pre> <p>I link to the right section of the docs is fine, you don't need to write the code for me (although I won't complain :) ). I'd like to know what the factory looks like, and also the registry code. </p>
    singulars
    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