Skip to content

Commit bb4f92b

Browse files
committed
Documentation Update for 4.6.0
1 parent 82270d2 commit bb4f92b

File tree

62 files changed

+379
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+379
-378
lines changed

autofactory/index.html

100644100755
+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
3232
<div class="container">
3333
<div class="navbar-header">
34-
<a href="/" class="navbar-brand">StructureMap 4.5.3</a>
34+
<a href="/" class="navbar-brand">StructureMap 4.6.0</a>
3535
</div>
3636
<nav class="collapse navbar-collapse" role="navigation">
3737
<ul class="nav navbar-nav pull-right">
@@ -74,7 +74,7 @@
7474

7575
<div class="col-md-3" id="leftCol">
7676
<ul class="nav nav-stacked affix" id="sidebar">
77-
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.5.3" width="210" height="210"></h3></li>
77+
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.6.0" width="210" height="210"></h3></li>
7878
<li><h3 class="no-margin">Next</h3><p><a href="/best-practices">Best Practices</a></p></li>
7979
<li><h3 class="no-margin">Previous</h3><a href="/dynamic-interception">Aspect Oriented Programming with StructureMap.DynamicInterception</a></p></li>
8080
</ul>
@@ -91,13 +91,13 @@ <h1>Auto-factories <a href="https://github.com/structuremap/structuremap/blob/ma
9191
<!--title:Auto-factories-->
9292
<div class="alert alert-info" role="alert">You need to install <a href="https://www.nuget.org/packages/StructureMap.Autofactory">StructureMap.Autofactory</a> package to use the functionality described below.</div>
9393
<p>When you need to implement <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory</a>, StructureMap offers a way to do it for you. Let's say you have</p>
94-
<pre><code class="language-csharp">&#xD;&#xA;public interface IDummyService&#xD;&#xA;{&#xD;&#xA; string Name { get; }&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
94+
<pre><code class="language-csharp">&#xA;public interface IDummyService&#xA;{&#xA; string Name { get; }&#xA;}&#xA;&#xA;</code></pre>
9595
with implementation
96-
<pre><code class="language-csharp">&#xD;&#xA;public class DummyService : IDummyService&#xD;&#xA;{&#xD;&#xA; public string Name { get; set; }&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
96+
<pre><code class="language-csharp">&#xA;public class DummyService : IDummyService&#xA;{&#xA; public string Name { get; set; }&#xA;}&#xA;&#xA;</code></pre>
9797
<p>Now you declare an interface for your factory:</p>
98-
<pre><code class="language-csharp">&#xD;&#xA;public interface ISimpleDummyFactory&#xD;&#xA;{&#xD;&#xA; IDummyService CreateDummyService();&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
98+
<pre><code class="language-csharp">&#xA;public interface ISimpleDummyFactory&#xA;{&#xA; IDummyService CreateDummyService();&#xA;}&#xA;&#xA;</code></pre>
9999
<p>All you need to do is to call <code>CreateFactory</code> when configuring the container as shown below:</p>
100-
<pre><code class="language-csharp">&#xD;&#xA;[Fact]&#xD;&#xA;public void Simple_factory_creation()&#xD;&#xA;{&#xD;&#xA; var container = new Container(cfg =&gt;&#xD;&#xA; {&#xD;&#xA; cfg.For&lt;IDummyService&gt;().Use&lt;DummyService&gt;();&#xD;&#xA; cfg.For&lt;ISimpleDummyFactory&gt;().CreateFactory();&#xD;&#xA; });&#xD;&#xA;&#xD;&#xA; var factory = container.GetInstance&lt;ISimpleDummyFactory&gt;();&#xD;&#xA;&#xD;&#xA; var component = factory.CreateDummyService();&#xD;&#xA;&#xD;&#xA; component.ShouldNotBeNull();&#xD;&#xA; component.ShouldBeOfType&lt;DummyService&gt;();&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
100+
<pre><code class="language-csharp">&#xA;[Fact]&#xA;public void Simple_factory_creation()&#xA;{&#xA; var container = new Container(cfg =&gt;&#xA; {&#xA; cfg.For&lt;IDummyService&gt;().Use&lt;DummyService&gt;();&#xA; cfg.For&lt;ISimpleDummyFactory&gt;().CreateFactory();&#xA; });&#xA;&#xA; var factory = container.GetInstance&lt;ISimpleDummyFactory&gt;();&#xA;&#xA; var component = factory.CreateDummyService();&#xA;&#xA; component.ShouldNotBeNull();&#xA; component.ShouldBeOfType&lt;DummyService&gt;();&#xA;}&#xA;&#xA;</code></pre>
101101
<h2 id="default-convention">Default convention</h2>
102102
<p>As for now, Auto-factories support two types of methods:</p>
103103
<ol>
@@ -112,13 +112,13 @@ <h2 id="default-convention">Default convention</h2>
112112
</ol>
113113
<p>Any other method that has the return type (i.e. doesn't return <code>void</code>), is treated as a factory method. In addition, if the method name starts with <code>GetNamed</code>, the first method argument is used as the name for the named instance. All the rest arguments are passed as <a href="/registration/inline-dependencies">explicit arguments</a> to the implementation constructor.</p>
114114
<p>It is much easier to see it on an example:</p>
115-
<pre><code class="language-csharp">&#xD;&#xA;public interface IDummyFactory&#xD;&#xA;{&#xD;&#xA; // This method will return the names of all registered implementations of TService.&#xD;&#xA; IList&lt;string&gt; GetNames&lt;TService&gt;();&#xD;&#xA;&#xD;&#xA; // This method will just create the default IDummyService implementation.&#xD;&#xA; IDummyService CreateDummyService();&#xD;&#xA;&#xD;&#xA; // This method will just create the default IDummyService implementation and pass namePart1 and namePart2 as&#xD;&#xA; // dependencies.&#xD;&#xA; IDummyService CreateDummyService(string namePart1, string namePart2);&#xD;&#xA;&#xD;&#xA; // This method will create IDummyService implementation with serviceName name.&#xD;&#xA; IDummyService GetNamedDummyService(string serviceName, string namePart1, string namePart2);&#xD;&#xA;&#xD;&#xA; // Generic methods are also allowed as factory methods.&#xD;&#xA; TService CreateService&lt;TService&gt;();&#xD;&#xA;&#xD;&#xA; // Something that is common for event-sourcing implementations.&#xD;&#xA; IHandler&lt;TMessage&gt; CreateHandler&lt;TMessage&gt;();&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
115+
<pre><code class="language-csharp">&#xA;public interface IDummyFactory&#xA;{&#xA; // This method will return the names of all registered implementations of TService.&#xA; IList&lt;string&gt; GetNames&lt;TService&gt;();&#xA;&#xA; // This method will just create the default IDummyService implementation.&#xA; IDummyService CreateDummyService();&#xA;&#xA; // This method will just create the default IDummyService implementation and pass namePart1 and namePart2 as&#xA; // dependencies.&#xA; IDummyService CreateDummyService(string namePart1, string namePart2);&#xA;&#xA; // This method will create IDummyService implementation with serviceName name.&#xA; IDummyService GetNamedDummyService(string serviceName, string namePart1, string namePart2);&#xA;&#xA; // Generic methods are also allowed as factory methods.&#xA; TService CreateService&lt;TService&gt;();&#xA;&#xA; // Something that is common for event-sourcing implementations.&#xA; IHandler&lt;TMessage&gt; CreateHandler&lt;TMessage&gt;();&#xA;}&#xA;&#xA;</code></pre>
116116
<h2 id="custom-convention">Custom convention</h2>
117117
<p>If the default convention doesn't work for you, you can create and use your custom convention. All you need is to implement <code>IAutoFactoryConventionProvider</code> and use the corresponding <code>CreateFactory</code> overload. <code>IAutoFactoryConventionProvider</code> has a single method to implement:</p>
118118
<pre><code>IAutoFactoryMethodDefinition GetMethodDefinition(MethodInfo methodInfo, IList&lt;object&gt; arguments);
119119
</code></pre>
120120
<p><code>IAutoFactoryMethodDefinition</code> is defined as follows:</p>
121-
<pre><code class="language-csharp">&#xD;&#xA;/// &lt;summary&gt;&#xD;&#xA;/// Describes how AutoFactory should treat the specific method declared in an abstract factory interface.&#xD;&#xA;/// &lt;/summary&gt;&#xD;&#xA;public interface IAutoFactoryMethodDefinition&#xD;&#xA;{&#xD;&#xA; /// &lt;summary&gt;&#xD;&#xA; /// The method type. See &lt;see cref=&quot;AutoFactoryMethodType&quot;/&gt; for possible values.&#xD;&#xA; /// &lt;/summary&gt;&#xD;&#xA; AutoFactoryMethodType MethodType { get; }&#xD;&#xA;&#xD;&#xA; /// &lt;summary&gt;&#xD;&#xA; /// The instance type to create.&#xD;&#xA; /// &lt;/summary&gt;&#xD;&#xA; Type InstanceType { get; }&#xD;&#xA;&#xD;&#xA; /// &lt;summary&gt;&#xD;&#xA; /// The instance name if available.&#xD;&#xA; /// &lt;/summary&gt;&#xD;&#xA; string InstanceName { get; }&#xD;&#xA;&#xD;&#xA; /// &lt;summary&gt;&#xD;&#xA; /// Explicit arguments if available.&#xD;&#xA; /// &lt;/summary&gt;&#xD;&#xA; ExplicitArguments ExplicitArguments { get; }&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;</code></pre>
121+
<pre><code class="language-csharp">&#xA;/// &lt;summary&gt;&#xA;/// Describes how AutoFactory should treat the specific method declared in an abstract factory interface.&#xA;/// &lt;/summary&gt;&#xA;public interface IAutoFactoryMethodDefinition&#xA;{&#xA; /// &lt;summary&gt;&#xA; /// The method type. See &lt;see cref=&quot;AutoFactoryMethodType&quot;/&gt; for possible values.&#xA; /// &lt;/summary&gt;&#xA; AutoFactoryMethodType MethodType { get; }&#xA;&#xA; /// &lt;summary&gt;&#xA; /// The instance type to create.&#xA; /// &lt;/summary&gt;&#xA; Type InstanceType { get; }&#xA;&#xA; /// &lt;summary&gt;&#xA; /// The instance name if available.&#xA; /// &lt;/summary&gt;&#xA; string InstanceName { get; }&#xA;&#xA; /// &lt;summary&gt;&#xA; /// Explicit arguments if available.&#xA; /// &lt;/summary&gt;&#xA; ExplicitArguments ExplicitArguments { get; }&#xA;}&#xA;&#xA;</code></pre>
122122

123123
</div>
124124

best-practices/index.html

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
3232
<div class="container">
3333
<div class="navbar-header">
34-
<a href="/" class="navbar-brand">StructureMap 4.5.3</a>
34+
<a href="/" class="navbar-brand">StructureMap 4.6.0</a>
3535
</div>
3636
<nav class="collapse navbar-collapse" role="navigation">
3737
<ul class="nav navbar-nav pull-right">
@@ -74,7 +74,7 @@
7474

7575
<div class="col-md-3" id="leftCol">
7676
<ul class="nav nav-stacked affix" id="sidebar">
77-
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.5.3" width="210" height="210"></h3></li>
77+
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.6.0" width="210" height="210"></h3></li>
7878
<li><h3 class="no-margin">Next</h3><p><a href="/history">History</a></p></li>
7979
<li><h3 class="no-margin">Previous</h3><a href="/autofactory">Auto-factories</a></p></li>
8080
</ul>

diagnostics/build-plans/index.html

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
3232
<div class="container">
3333
<div class="navbar-header">
34-
<a href="/" class="navbar-brand">StructureMap 4.5.3</a>
34+
<a href="/" class="navbar-brand">StructureMap 4.6.0</a>
3535
</div>
3636
<nav class="collapse navbar-collapse" role="navigation">
3737
<ul class="nav navbar-nav pull-right">
@@ -74,7 +74,7 @@
7474

7575
<div class="col-md-3" id="leftCol">
7676
<ul class="nav nav-stacked affix" id="sidebar">
77-
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.5.3" width="210" height="210"></h3></li>
77+
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.6.0" width="210" height="210"></h3></li>
7878
<li><h3 class="no-margin">Next</h3><p><a href="/diagnostics/using-the-container-model">Using the Container Model</a></p></li>
7979
<li><h3 class="no-margin">Previous</h3><a href="/diagnostics/environment-tests">Environment Tests</a></p></li>
8080
</ul>
@@ -101,7 +101,7 @@ <h1>Build Plans <a href="https://github.com/structuremap/structuremap/blob/maste
101101
<li>Description of any Lambda or <code>Func&lt;T&gt;</code> that is used to construct the Instance object</li>
102102
</ol>
103103
<p>To retrieve the build plan for a configured Instance, use the queryable <code>Container.Model</code> to find the configured Instance and call <code>DescribeBuildPlan(int maxDepth)</code> to get the textual report as shown in this sample below:</p>
104-
<pre><code class="language-csharp">&#xD;&#xA;var container = Container.For&lt;VisualizationRegistry&gt;();&#xD;&#xA;&#xD;&#xA;var description = container.Model.For&lt;IDevice&gt;().Default&#xD;&#xA; .DescribeBuildPlan();&#xD;&#xA;&#xD;&#xA;Debug.WriteLine(description);&#xD;&#xA;</code></pre>
104+
<pre><code class="language-csharp">&#xA;var container = Container.For&lt;VisualizationRegistry&gt;();&#xA;&#xA;var description = container.Model.For&lt;IDevice&gt;().Default&#xA; .DescribeBuildPlan();&#xA;&#xA;Debug.WriteLine(description);&#xA;</code></pre>
105105
<p>The result of the code above is this textual representation of how StructureMap will build and/or resolve the default of the <code>IDevice</code> plugin type:</p>
106106
<pre>
107107
PluginType: StructureMap.Testing.Diagnostics.IDevice
@@ -116,7 +116,7 @@ <h1>Build Plans <a href="https://github.com/structuremap/structuremap/blob/maste
116116

117117
</pre>
118118
<p>For another example, you can retrieve the build plan for a named instance of a certain build plan with this code:</p>
119-
<pre><code class="language-csharp">&#xD;&#xA;var description = theContainer.Model.For&lt;IDevice&gt;()&#xD;&#xA; .Find(&quot;A&quot;)&#xD;&#xA; .DescribeBuildPlan();&#xD;&#xA;</code></pre>
119+
<pre><code class="language-csharp">&#xA;var description = theContainer.Model.For&lt;IDevice&gt;()&#xA; .Find(&quot;A&quot;)&#xA; .DescribeBuildPlan();&#xA;</code></pre>
120120
<p>See <a href="/diagnostics/using-the-container-model">Using the Container Model</a> for more information on using <code>Container.Model</code>.</p>
121121
<p>You can find many more examples of finding the build plan description from <code>Container.Model</code> from the <a href="https://github.com/structuremap/structuremap/blob/master/src/StructureMap.Testing/Diagnostics/BuildPlanVisualizationSmokeTester.cs">unit tests in the StructureMap codebase</a>.</p>
122122

diagnostics/environment-tests/index.html

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
3232
<div class="container">
3333
<div class="navbar-header">
34-
<a href="/" class="navbar-brand">StructureMap 4.5.3</a>
34+
<a href="/" class="navbar-brand">StructureMap 4.6.0</a>
3535
</div>
3636
<nav class="collapse navbar-collapse" role="navigation">
3737
<ul class="nav navbar-nav pull-right">
@@ -74,7 +74,7 @@
7474

7575
<div class="col-md-3" id="leftCol">
7676
<ul class="nav nav-stacked affix" id="sidebar">
77-
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.5.3" width="210" height="210"></h3></li>
77+
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.6.0" width="210" height="210"></h3></li>
7878
<li><h3 class="no-margin">Next</h3><p><a href="/diagnostics/build-plans">Build Plans</a></p></li>
7979
<li><h3 class="no-margin">Previous</h3><a href="/diagnostics/validating-container-configuration">Validating Container Configuration</a></p></li>
8080
</ul>
@@ -98,7 +98,7 @@ <h1>Environment Tests <a href="https://github.com/structuremap/structuremap/blob
9898
</ul>
9999
<p>The deployments still frequently failed, but we were able to spot <strong>and diagnose</strong> the underlying problems much faster with our new environment tests than we could before by trying to run and debug the not-quite-valid application.</p>
100100
<p>One of the mechanisms we used for these environment tests was StructureMap's ability to mark methods on configured types as environment tests with the <code>[ValidationMethod]</code> attribute as shown below:</p>
101-
<pre><code class="language-csharp">&#xD;&#xA;public class Database : IDatabase&#xD;&#xA;{&#xD;&#xA; [ValidationMethod]&#xD;&#xA; public void TryToConnect()&#xD;&#xA; {&#xD;&#xA; // try to open a connection to the configured&#xD;&#xA; // database connection string&#xD;&#xA;&#xD;&#xA; // throw an exception if the database cannot&#xD;&#xA; // be reached&#xD;&#xA; }&#xD;&#xA;}&#xD;&#xA;</code></pre>
101+
<pre><code class="language-csharp">&#xA;public class Database : IDatabase&#xA;{&#xA; [ValidationMethod]&#xA; public void TryToConnect()&#xA; {&#xA; // try to open a connection to the configured&#xA; // database connection string&#xA;&#xA; // throw an exception if the database cannot&#xA; // be reached&#xA; }&#xA;}&#xA;</code></pre>
102102
<p>Used in conjunction with <a href="/diagnostics/validating-container-configuration">StructureMap's ability to validate a container</a>, you can use this technique to quickly support environment tests embedded into your system code.</p>
103103

104104
</div>

diagnostics/index.html

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
3232
<div class="container">
3333
<div class="navbar-header">
34-
<a href="/" class="navbar-brand">StructureMap 4.5.3</a>
34+
<a href="/" class="navbar-brand">StructureMap 4.6.0</a>
3535
</div>
3636
<nav class="collapse navbar-collapse" role="navigation">
3737
<ul class="nav navbar-nav pull-right">
@@ -74,7 +74,7 @@
7474

7575
<div class="col-md-3" id="leftCol">
7676
<ul class="nav nav-stacked affix" id="sidebar">
77-
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.5.3" width="210" height="210"></h3></li>
77+
<li><h3><img src="/content/images/structuremap-logo-210x210.png" alt="StructureMap 4.6.0" width="210" height="210"></h3></li>
7878
<li><h3 class="no-margin">Next</h3><p><a href="/diagnostics/whatdoihave">WhatDoIHave()</a></p></li>
7979
<li><h3 class="no-margin">Previous</h3><a href="/interpreting-exceptions">Interpreting Exceptions</a></p></li>
8080
</ul>

0 commit comments

Comments
 (0)