Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any reason to not use my IoC as a general Settings Repository?
    primarykey
    data
    text
    <p>Suppose that the <strong>ApplicationSettings</strong> class is a general repository of settings that apply to my application such as TimeoutPeriod, DefaultUnitOfMeasure, HistoryWindowSize, etc... And let's say MyClass makes use of one of those settings - DefaultUnitOfMeasure.</p> <p>My reading of proper use of Inversion of Control Containers - and please correct me if I'm wrong on this - is that you define the dependencies of a class in its constructor:</p> <pre><code>public class MyClass { public MyClass(IDataSource ds, UnitOfMeasure default_uom) {...} } </code></pre> <p>and then call instantiate your class with something like</p> <pre><code>var mc = IoC.Container.Resolve&lt;MyClass&gt;(); </code></pre> <p>Where <strong>IDataSource</strong> has been assigned a concrete implementation and default_uom has been wired up to instantiate from the <strong>ApplicationSettings.DefaultUnitOfMeasure</strong> property. I've got to wonder however, if all these hoops are really that necessary to jump through. What trouble am I setting myself up for should I do</p> <pre><code>public class MyClass { public MyClass(IDataSource ds) { UnitOfMeasure duom = IoC.Container.Resolve&lt;UnitOfMeasure&gt;("default_uom"); } } </code></pre> <p>Yes, many of my classes end up with a dependency on <strong>IoC.Container</strong> but that is a dependency that most of my classes will have anyways. It seems like I maybe should make full use of it as long as the classes are coupled. Please Agile gurus, tell me where I'm wrong.</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.
 

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