Skip to content

Commit

Permalink
Updated html docs
Browse files Browse the repository at this point in the history
  • Loading branch information
svermeulen committed Apr 3, 2017
1 parent 893ffab commit f1fd7aa
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 48 deletions.
18 changes: 9 additions & 9 deletions Build/CreateHtmlDocs.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@echo off

grip %~dp0\..\README.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\README.html
grip %~dp0\..\Documentation\AutoMocking.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\AutoMocking.html
grip %~dp0\..\Documentation\CheatSheet.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\CheatSheet.html
grip %~dp0\..\Documentation\Signals.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\Signals.html
grip %~dp0\..\Documentation\Factories.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\Factories.html
grip %~dp0\..\Documentation\MemoryPools.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\MemoryPools.html
grip %~dp0\..\Documentation\ReleaseNotes.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\ReleaseNotes.html
grip %~dp0\..\Documentation\SubContainers.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\SubContainers.html
grip %~dp0\..\Documentation\WritingAutomatedTests.md --export %~dp0\..\UnityProject\Assets\Zenject\Documentation\WritingAutomatedTests.html
grip %~dp0\..\README.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\README.html
grip %~dp0\..\Documentation\AutoMocking.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\AutoMocking.html
grip %~dp0\..\Documentation\CheatSheet.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\CheatSheet.html
grip %~dp0\..\Documentation\Signals.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\Signals.html
grip %~dp0\..\Documentation\Factories.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\Factories.html
grip %~dp0\..\Documentation\MemoryPools.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\MemoryPools.html
grip %~dp0\..\Documentation\ReleaseNotes.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\ReleaseNotes.html
grip %~dp0\..\Documentation\SubContainers.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\SubContainers.html
grip %~dp0\..\Documentation\WritingAutomatedTests.md --export %~dp0\..\UnityProject\Assets\Plugins\Zenject\Documentation\WritingAutomatedTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ <h2>

<p>The dynamic parameters that are provided to the Enemy constructor are declared by using generic arguments to the Factory&lt;&gt; base class of Enemy.Factory. This will add a method to Enemy.Factory that takes the parameters with the given types, which is called by EnemySpawner.</p>

<p>Note: You can have multiple parameters declared with the same type. In this case, the order that the values are given to the factory will match the parameter order - assuming that you are using constructor or method injection. However, if you are using field or property injection, then the order that values are injected is not guaranteed to follow the declaration order, since these fields are retrieved using Type.GetFields which does not guarantee order as described <a href="https://msdn.microsoft.com/en-us/library/ch9714z3.aspx">here</a></p>

<p>In this case, they will be injected in the same order that they are declared in your class. In the case of constructor/inject-method parameters, this will be the order the parameters are given in, or in the case of fields the order will be from top to bottom that they are declared in. Constructor parameters are processed first, then fields, then properties, then inject methods.</p>

<p>There is no requirement that the <code>Enemy.Factory</code> class be a nested class within Enemy, however we have found this to be a very useful convention. <code>Enemy.Factory</code> is always intentionally left empty and simply derives from the built-in Zenject <code>Factory&lt;&gt;</code> class, which handles the work of using the DiContainer to construct a new instance of Enemy.</p>

<p>The reason that we don't use the <code>Factory&lt;Enemy&gt;</code> class directly is because this can become error prone when adding/removing parameters and also can get verbose since the parameter types must be declared whenever you refer to this class. This is error prone because if for example you add a parameter to enemy and change the factory from <code>Factory&lt;Enemy&gt;</code> to <code>Factory&lt;float, Enemy&gt;</code>, any references to <code>Factory&lt;Enemy&gt;</code> will not be resolved. And this will not be caught at compile time and instead will only be seen during validation or runtime. So we recommend always using an empty class that derives from <code>Factory&lt;&gt;</code> instead.</p>
Expand Down Expand Up @@ -258,6 +262,8 @@ <h2>

<p>Using FromSubContainerResolve can be particularly useful if your dynamically created object has a lot of its own dependencies. You can have it behave like a Facade. See the Subcontainers section for details on nested containers / facades.</p>

<p>Also note that you for dynamically instantiated MonoBehaviours (for example when using FromComponentInNewPrefab with BindFactory) injection should always occur before Awake and Start, so you can use Awake and Start for initialization logic and use the inject method strictly for saving dependencies (ie. similar to constructors for non-monobehaviours)</p>

<h2>
<a id="user-content-abstract-factories" class="anchor" href="#abstract-factories" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><a id="user-content-abstract-factories"></a>Abstract Factories</h2>

Expand Down
28 changes: 26 additions & 2 deletions UnityProject/Assets/Plugins/Zenject/Documentation/MemoryPools.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h2>
<p>The full format of the binding is the following:</p>

<pre>
Container.BindMemoryPool&lt;<b>Param1Type, Param2Type, etc..., ObjectType, MemoryPoolType</b>&gt;()
Container.BindMemoryPool&lt;<b>ObjectType, MemoryPoolType</b>&gt;()
.With<b>(InitialSize|FixedSize)</b>()
.ExpandBy<b>(OneAtATime|Doubling)</b>()
.To&lt;<b>ResultType</b>&gt;()
Expand Down Expand Up @@ -448,7 +448,7 @@ <h2>

<p>The main difference here is that Foo.Pool now derives from MonoMemoryPool instead of MemoryPool. MonoMemoryPool is a helper class that will automatically enable and disable the game object for us when it is added/removed from the pool. The implementation for MonoMemoryPool is simply this:</p>

<div class="highlight highlight-source-cs"><pre><span class="pl-k">public</span> abstract <span class="pl-k">class</span> <span class="pl-en">MonoMemoryPool</span>&lt;<span class="pl-en">TParam1</span>, <span class="pl-en">TValue</span>&gt; : <span class="pl-en">MemoryPool</span>&lt;<span class="pl-en">TParam1</span>, <span class="pl-en">TValue</span>&gt;
<div class="highlight highlight-source-cs"><pre><span class="pl-k">public</span> <span class="pl-k">abstract</span> <span class="pl-k">class</span> <span class="pl-en">MonoMemoryPool</span>&lt;<span class="pl-en">TParam1</span>, <span class="pl-en">TValue</span>&gt; : <span class="pl-en">MemoryPool</span>&lt;<span class="pl-en">TParam1</span>, <span class="pl-en">TValue</span>&gt;
<span class="pl-k">where</span> <span class="pl-en">TValue</span> : <span class="pl-en">Component</span>
{
<span class="pl-k">protected</span> <span class="pl-k">override</span> <span class="pl-k">void</span> <span class="pl-en">OnCreated</span>(<span class="pl-en">TValue</span> <span class="pl-smi">item</span>)
Expand Down Expand Up @@ -536,6 +536,30 @@ <h2>

<p>We might also want to add a Reset() method to the IFoo interface as well here, and call that on Reinitialize()</p>

<h3>
<a id="user-content-instantiating-memory-pools-directly" class="anchor" href="#instantiating-memory-pools-directly" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><a id="user-content-instantiating-directory"></a>Instantiating Memory Pools Directly</h3>

<p>For complex scenarios involing custom factories, it might be desirable to directly instantiate memory pools. In this case, you just have to make sure to provide an IFactory&lt;&gt; derived class to be used for creating new instances and all the settings information that would normally be provided via the bind statements. For example:</p>

<div class="highlight highlight-source-cs"><pre><span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-en">BarFactory</span> : <span class="pl-en">IFactory</span>&lt;<span class="pl-en">Bar</span>&gt;
{
<span class="pl-k">public</span> <span class="pl-en">Bar</span> <span class="pl-en">Create</span>()
{
...
[Custom creation logic]
...
}
}

<span class="pl-k">var</span> <span class="pl-en">settings </span>= <span class="pl-k">new</span> <span class="pl-en">MemoryPoolSettings</span>()
{
InitialSize = <span class="pl-c1">1</span>,
ExpandMethod = PoolExpandMethods.Double,
};

<span class="pl-k">var</span> <span class="pl-en">pool </span>= _container.<span class="pl-en">Instantiate</span>&lt;<span class="pl-en">MemoryPool</span>&lt;<span class="pl-en">Bar</span>&gt;&gt;(
new object[] { settings, <span class="pl-k">new</span> <span class="pl-en">MyBarFactory</span>&lt;Bar&gt;() });</pre></div>

</article>
</div>
</div>
Expand Down
Loading

0 comments on commit f1fd7aa

Please sign in to comment.