<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>ninject Wiki &amp; Documentation Rss Feed</title><link>http://ninject.codeplex.com/Wiki/View.aspx?title=Home</link><description>ninject Wiki Rss Description</description><item><title>New Comment on "User Guide"</title><link>https://ninject.codeplex.com/wikipage?title=User Guide&amp;ANCHOR#C27570</link><description>this user guide is about niject1.0,is there any documentation about ninject2.0&amp;#63;where can i read it&amp;#63;</description><author>ncistgg</author><pubDate>Thu, 23 May 2013 09:55:47 GMT</pubDate><guid isPermaLink="false">New Comment on "User Guide" 20130523095547A</guid></item><item><title>New Comment on "Modules and the Kernel"</title><link>http://ninject.codeplex.com/wikipage?title=Modules and the Kernel&amp;ANCHOR#C26299</link><description>Bind&amp;#60;IWeapon&amp;#62;&amp;#40;&amp;#41;.To&amp;#60;Sword&amp;#62;&amp;#40;&amp;#41;&amp;#59; &amp;#10;I need &amp;#34;Bind&amp;#34; example please</description><author>loopdebugger</author><pubDate>Thu, 24 Jan 2013 18:09:08 GMT</pubDate><guid isPermaLink="false">New Comment on "Modules and the Kernel" 20130124060908P</guid></item><item><title>New Comment on "Activation Behaviors"</title><link>http://ninject.codeplex.com/wikipage?title=Activation Behaviors&amp;ANCHOR#C26298</link><description>wait.... &amp;#10;what is &amp;#34;Bind&amp;#34;&amp;#63; I can understand that part... is a method i know but what it does&amp;#63;</description><author>loopdebugger</author><pubDate>Thu, 24 Jan 2013 18:07:18 GMT</pubDate><guid isPermaLink="false">New Comment on "Activation Behaviors" 20130124060718P</guid></item><item><title>New Comment on "Injection Patterns"</title><link>http://ninject.codeplex.com/wikipage?title=Injection Patterns&amp;ANCHOR#C23948</link><description>Hi,&amp;#10;If one leave off InjectAttribute, then&amp;#58;&amp;#10;&amp;#10;3. If the type has more than one constructor, and has no default &amp;#40;parameterless&amp;#41; constructor available, Ninject will call first ctor that even partially matches. For example we have test code&amp;#58;&amp;#10;&amp;#10; using &amp;#40;IKernel kernel &amp;#61; new StandardKernel&amp;#40;&amp;#41;&amp;#41; &amp;#123;&amp;#10;                kernel.Bind&amp;#60;ITaxCalculator&amp;#62;&amp;#40;&amp;#41;.To&amp;#60;TaxCalculator&amp;#62;&amp;#40;&amp;#41;.WithConstructorArgument&amp;#40;&amp;#34;rate&amp;#34;, .2M&amp;#41;&amp;#59;&amp;#10;                var sale3 &amp;#61; kernel.Get&amp;#60;Sale3&amp;#62;&amp;#40;&amp;#41;&amp;#59;&amp;#10;&amp;#10;                Assert.IsNotNull&amp;#40;sale3&amp;#41;&amp;#59;&amp;#10;            &amp;#125;&amp;#10;&amp;#10;And class to test&amp;#58;&amp;#10;&amp;#10;public class Sale3 &amp;#123;&amp;#10;&amp;#10;        private ITaxCalculator _taxCalculator&amp;#59;      &amp;#10;&amp;#10;        public Sale3&amp;#40;ITaxCalculator taxCalculator&amp;#41; &amp;#123;&amp;#10;            _taxCalculator &amp;#61; taxCalculator&amp;#59;&amp;#10;        &amp;#125;&amp;#10;&amp;#10;        public Sale3&amp;#40;ITaxCalculator taxCalc, int testInteger&amp;#41; &amp;#123;&amp;#10;            _taxCalculator &amp;#61; taxCalc&amp;#59;&amp;#10;        &amp;#125;&amp;#10;    &amp;#125;&amp;#10;&amp;#10;In this case test will be run successfully. If we reorder constructors that the one with integer as input parameter will be first, test will fail.&amp;#10;&amp;#10;So I believe that  under the hood Ninject searches for first constructor that accepts desired Interface as an input paramter and then invokes this ctor.&amp;#10;&amp;#10;Am I correct&amp;#63;</description><author>skrzeczowas</author><pubDate>Tue, 05 Jun 2012 09:32:50 GMT</pubDate><guid isPermaLink="false">New Comment on "Injection Patterns" 20120605093250A</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C23260</link><description>ooops... I guess I should keep reading</description><author>hbrizuela</author><pubDate>Wed, 11 Apr 2012 20:12:38 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20120411081238P</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C23259</link><description>having Bind&amp;#60;IWeapon&amp;#62;&amp;#40;&amp;#41;.To&amp;#60;Sword&amp;#62;&amp;#40;&amp;#41;&amp;#59;&amp;#10;means whenever I instantiate the class samurai my instance will have a weapon of type sword. Am I wrong&amp;#63;&amp;#10;what if I want to create a list or Enumerable of samurai with different kind of weapon.&amp;#10;will I have to do it by hand&amp;#63;</description><author>hbrizuela</author><pubDate>Wed, 11 Apr 2012 20:10:34 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20120411081034P</guid></item><item><title>New Comment on "user guide"</title><link>http://ninject.codeplex.com/wikipage?title=user guide&amp;ANCHOR#C16447</link><description>i m glad i found ur blog.Not everyone can provide information with proper flow. Good post. I am going to save the URL and will definitely visit again. Keep it up.&amp;#60;a  href&amp;#61;&amp;#34;http&amp;#58;&amp;#47;&amp;#47;www.realcourseworkwriting.com&amp;#34; rel&amp;#61;&amp;#34;dofollow&amp;#34;&amp;#62;coursework writing&amp;#60;&amp;#47;a&amp;#62; &amp;#124; &amp;#60;a  href&amp;#61;&amp;#34;http&amp;#58;&amp;#47;&amp;#47;www.realresearchwriting.com&amp;#34; rel&amp;#61;&amp;#34;dofollow&amp;#34;&amp;#62;research writing&amp;#60;&amp;#47;a&amp;#62;</description><author>jameskerry486</author><pubDate>Sat, 24 Jul 2010 04:46:13 GMT</pubDate><guid isPermaLink="false">New Comment on "user guide" 20100724044613A</guid></item><item><title>New Comment on "Modules and the Kernel"</title><link>http://ninject.codeplex.com/wikipage?title=Modules and the Kernel&amp;ANCHOR#C15318</link><description>shit&amp;#33;</description><author>ng2tuan</author><pubDate>Tue, 30 Mar 2010 13:54:30 GMT</pubDate><guid isPermaLink="false">New Comment on "Modules and the Kernel" 20100330015430P</guid></item><item><title>New Comment on "User Guide"</title><link>http://ninject.codeplex.com/wikipage?title=User Guide&amp;ANCHOR#C14992</link><description>Any chance I can get write perms so I can update this documentation &amp;#40;or create new documentation&amp;#41; for Ninject 2&amp;#63;</description><author>chillitom</author><pubDate>Wed, 24 Feb 2010 14:27:12 GMT</pubDate><guid isPermaLink="false">New Comment on "User Guide" 20100224022712P</guid></item><item><title>New Comment on "Dependency Injection By Hand"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection By Hand&amp;ANCHOR#C14941</link><description>This is just me being anal, but the actual output of warrior1.Attack&amp;#40;&amp;#34;the evildoers&amp;#34;&amp;#41; is &amp;#34;Pierced the evildoers&amp;#39;s armor.&amp;#34;.</description><author>DanAtkinson</author><pubDate>Fri, 19 Feb 2010 10:27:36 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection By Hand" 20100219102736A</guid></item><item><title>New Comment on "User Guide"</title><link>http://ninject.codeplex.com/wikipage?title=User Guide&amp;ANCHOR#C14895</link><description>This documentation is not very complete. Where is detailed explanations of, for example, the contextual binding parameters and valid objects etc to use&amp;#63; E.g. - what is When.Request.Context.Target, and why doesn&amp;#39;t it work with Only or OnlyIf bindings&amp;#63;</description><author>bensturley</author><pubDate>Tue, 16 Feb 2010 13:06:19 GMT</pubDate><guid isPermaLink="false">New Comment on "User Guide" 20100216010619P</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C14776</link><description>You should probably keep reading.  If you get two more sections ahead, it&amp;#39;s all written out in fairly crystal clear detail.  Not only will you see the benefits of a container, but it will also let you extrapolate how it would save you &amp;#42;tons&amp;#42; of effort in a more complex scenario.</description><author>swingsetacid</author><pubDate>Mon, 01 Feb 2010 22:15:37 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20100201101537P</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C14409</link><description>It is hard to appreciate what an IoC &amp;#34;saves&amp;#34; until you need to construct an object that contains many dependencies that contain dependencies, which also contain dependencies and so on and so forth. These are just trivial examples to show the concept of DI via IoC &amp;#40;ninject&amp;#41;. You wouldn&amp;#39;t want to add the complexity of an IoC, unless you had and architecture that was suited to it&amp;#58; all objects that composed the final object followed the DI pattern.</description><author>jsmorris</author><pubDate>Sat, 12 Dec 2009 04:28:51 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20091212042851A</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C14395</link><description>Perhaps it would be more clear how this saves effort if the example showed how something would instantiate a Samurai instance once the attribute is in place&amp;#63;  You have to call a constructor and pass an IWeapon, so what&amp;#39;s Ninject doing that&amp;#39;s not on display here&amp;#63;</description><author>SittenSpynne</author><pubDate>Tue, 08 Dec 2009 23:27:09 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20091208112709P</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C14394</link><description>&amp;#64;Vaccanoll  See this post on Stacked Overflow which answers your question&amp;#58; http&amp;#58;&amp;#47;&amp;#47;stackoverflow.com&amp;#47;questions&amp;#47;871405&amp;#47;why-do-i-need-an-ioc-container-as-opposed-to-straightforward-di-code . In short, for simple applications you don&amp;#39;t gain much, but as the complexity of the application grows, it makes it a lot easier to maintain the wiring of your application and swap out implementations.</description><author>dschobel</author><pubDate>Tue, 08 Dec 2009 21:58:15 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20091208095815P</guid></item><item><title>New Comment on "Dependency Injection With Ninject"</title><link>http://ninject.codeplex.com/wikipage?title=Dependency Injection With Ninject&amp;ANCHOR#C14386</link><description>Maybe I am just dense, but I am not getting what this saves yet&amp;#63;  All the code from the &amp;#34;by hand&amp;#34; method seems to still be needed and the Samurai class is the same except it has the &amp;#91;Inject&amp;#93; tag.&amp;#10;&amp;#10;Though I do get that this is better than other models due to it not needing XML.... But what do we gain over doing it by hand&amp;#63;</description><author>vaccanoll</author><pubDate>Mon, 07 Dec 2009 22:38:19 GMT</pubDate><guid isPermaLink="false">New Comment on "Dependency Injection With Ninject" 20091207103819P</guid></item><item><title>Updated Wiki: How Injection Works</title><link>http://ninject.codeplex.com/Wiki/View.aspx?title=How Injection Works&amp;version=2</link><description>&lt;div class="wikidoc"&gt;Ninject relies on reflection to analyze the types that it works with. However, since repeating calls via reflection can be very slow, Ninject can also take advantage of the lightweight code generation system introduced in version 2.0 of the CLR. By default, the &lt;span class="codeInline"&gt;StandardKernel&lt;/span&gt; will create dynamic methods (via &lt;span class="codeInline"&gt;System.Reflection.Emit.DynamicMethod&lt;/span&gt;) that can be used to inject values into the different injection targets. These dynamic methods are then triggered via delegate calls.&lt;br /&gt;&lt;br /&gt;For example, given our &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; type:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;class&lt;/span&gt; Samurai {
  &lt;span style="color:Blue;"&gt;private&lt;/span&gt; &lt;span style="color:Blue;"&gt;readonly&lt;/span&gt; IWeapon _weapon;
  
  [Inject]
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; Samurai(IWeapon weapon) {
    _weapon = weapon;
  }
  
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; Attack(&lt;span style="color:Blue;"&gt;string&lt;/span&gt; target) {
    _weapon.Hit(target);
  }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;VB.NET:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt; Samurai
  &lt;span style="color:Blue;"&gt;Private&lt;/span&gt; &lt;span style="color:Blue;"&gt;ReadOnly&lt;/span&gt; _weapon &lt;span style="color:Blue;"&gt;As&lt;/span&gt; IWeapon

  &amp;lt;Inject()&amp;gt; _
  &lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt; &lt;span style="color:Blue;"&gt;New&lt;/span&gt;(&lt;span style="color:Blue;"&gt;ByVal&lt;/span&gt; weapon &lt;span style="color:Blue;"&gt;As&lt;/span&gt; IWeapon)
    _weapon = weapon
  &lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt;
  &lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt; Attack(&lt;span style="color:Blue;"&gt;ByVal&lt;/span&gt; target &lt;span style="color:Blue;"&gt;As&lt;/span&gt; &lt;span style="color:Blue;"&gt;String&lt;/span&gt;)
    _sword.Hit(target)
  &lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt;
&lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Ninject will create a dynamic method that (basically) looks like this:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;delegate&lt;/span&gt;(IWeapon weapon) {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Samurai(weapon);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Then, whenever the &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt; associated with the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; needs to create a new instance, it resolves the &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt; argument, and then passes it to the dynamic method, which in turn passes the &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt; to the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt;'s constructor and returns the created instance.&lt;br /&gt;&lt;br /&gt;Ninject can also be configured to use reflection for injection. Because there is some overhead involved with creating the dynamic methods, this can actually result in faster execution in some cases -- particularly when you have a large number of services, but they're all Singletons. &lt;br /&gt;&lt;br /&gt;Continue reading: &lt;a href="http://ninject.codeplex.com/Wiki/View.aspx?title=Contextual%20Binding&amp;referringTitle=Home"&gt;Contextual Binding&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>NotMyself</author><pubDate>Mon, 12 Oct 2009 15:52:20 GMT</pubDate><guid isPermaLink="false">Updated Wiki: How Injection Works 20091012035220P</guid></item><item><title>Updated Wiki: The Activation Process</title><link>http://ninject.codeplex.com/Wiki/View.aspx?title=The Activation Process&amp;version=2</link><description>&lt;div class="wikidoc"&gt;Quite a bit of magic happens inside of Ninject when you call the kernel's &lt;span class="codeInline"&gt;Get()&lt;/span&gt; method. Here's a rough sketch of the procedure:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;The binding of the type is resolved.&lt;/li&gt;
&lt;li&gt;The binding is used to create an activation plan, which describes the means by which the instance will be created and injected.&lt;/li&gt;
&lt;li&gt;An instance of the type is requested from the behavior defined in the activation plan. Depending on the behavior's implementation, the behavior may simply return an existing instance of the type, in which case the rest of the activation process is not executed.&lt;/li&gt;
&lt;li&gt;If the behavior indicates that a new instance of the type is necessary, it is requested from the binding's provider. The provider resolves any necessary arguments and calls the injection constructor.&lt;/li&gt;
&lt;li&gt;All properties are injected according to the activation plan.&lt;/li&gt;
&lt;li&gt;All methods are injected according to the activation plan.&lt;/li&gt;
&lt;li&gt;All fields are injected according to the activation plan.&lt;/li&gt;
&lt;li&gt;If the type implements the &lt;span class="codeInline"&gt;IInitializable&lt;/span&gt; interface, its &lt;span class="codeInline"&gt;Initialize()&lt;/span&gt; method is called.&lt;/li&gt;
&lt;li&gt;If the type implements the &lt;span class="codeInline"&gt;IStartable&lt;/span&gt; interface, its &lt;span class="codeInline"&gt;Start()&lt;/span&gt; method is called.&lt;/li&gt;&lt;/ol&gt;
&lt;br /&gt;This entire activation procedure can also be customized by altering the strategy chain used by the Activator kernel component. (More on customizations later.)&lt;br /&gt;&lt;br /&gt;Returning to our earlier example, we had a &lt;span class="codeInline"&gt;WarriorModule&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;class&lt;/span&gt; WarriorModule : StandardModule {
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;override&lt;/span&gt; Load() {
    Bind&amp;lt;IWeapon&amp;gt;().To&amp;lt;Sword&amp;gt;();
    Bind&amp;lt;Samurai&amp;gt;().ToSelf();
  }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;VB.NET:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt; WarriorModule
  &lt;span style="color:Blue;"&gt;Inherits&lt;/span&gt; StandardModule

  &lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Overrides&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt; Load()
      Bind(Of IWeapon).&lt;span style="color:Blue;"&gt;To&lt;/span&gt;(Of Sword)()
      Bind(Of Samurai).ToSelf()
  &lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt;
&lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;And we activated an instance of &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;class&lt;/span&gt; Program {
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; Main() {
    IKernel kernel = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; StandardKernel(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; WarriorModule());
    Samurai warrior = kernel.Get&amp;lt;Samurai&amp;gt;();
    warrior.Attack(&lt;span style="color:#A31515;"&gt;&amp;quot;the evildoers&amp;quot;&lt;/span&gt;);
  }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;VB.NET:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;Module&lt;/span&gt; Module1
  &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt; Main()
    &lt;span style="color:Blue;"&gt;Dim&lt;/span&gt; kernel &lt;span style="color:Blue;"&gt;As&lt;/span&gt; IKernel = &lt;span style="color:Blue;"&gt;New&lt;/span&gt; StandardKernel(&lt;span style="color:Blue;"&gt;New&lt;/span&gt; WarriorModule())
    &lt;span style="color:Blue;"&gt;Dim&lt;/span&gt; warrior &lt;span style="color:Blue;"&gt;As&lt;/span&gt; Samurai = kernel.&lt;span style="color:Blue;"&gt;Get&lt;/span&gt;(Of Samurai)()
    warrior.Attack(&lt;span style="color:#A31515;"&gt;&amp;quot;evil doers&amp;quot;&lt;/span&gt;)
  &lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Sub&lt;/span&gt;
&lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Module&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The activation process for the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; type is as follows. The number to the left indicates the depth at which the activation is occurring, and some steps have been left out for clarity:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;(1) The kernel resolves the self-binding for the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; type that was defined in the &lt;span class="codeInline"&gt;WarriorModule&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;(1) The kernel asks the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt;'s &lt;span class="codeInline"&gt;TransientBehavior&lt;/span&gt; to resolve an instance.&lt;/li&gt;
&lt;li&gt;(1) The Samurai's &lt;span class="codeInline"&gt;TransientBehavior&lt;/span&gt; asks the binding's provider to create a new instance.&lt;/li&gt;
&lt;li&gt;(2) The Samurai's &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt; asks the kernel to resolve an instance of &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;(2) The kernel resolves the binding from &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt; to &lt;span class="codeInline"&gt;Sword&lt;/span&gt; that was defined in the &lt;span class="codeInline"&gt;WarriorModule&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;(2) The kernel asks the &lt;span class="codeInline"&gt;Sword&lt;/span&gt;'s &lt;span class="codeInline"&gt;TransientBehavior&lt;/span&gt; to resolve an instance.&lt;/li&gt;
&lt;li&gt;(2) The &lt;span class="codeInline"&gt;Sword&lt;/span&gt;'s &lt;span class="codeInline"&gt;TransientBehavior&lt;/span&gt; asks the binding's provider to create a new instance.&lt;/li&gt;
&lt;li&gt;(2) The &lt;span class="codeInline"&gt;Sword&lt;/span&gt;'s &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt; calls the &lt;span class="codeInline"&gt;Sword&lt;/span&gt;'s parameterless constructor.&lt;/li&gt;
&lt;li&gt;(2) The kernel returns the newly-created instance of &lt;span class="codeInline"&gt;Sword&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;(1) The &lt;span class="codeInline"&gt;Samurai&lt;/span&gt;'s &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt; calls the &lt;span class="codeInline"&gt;Samurai&lt;/span&gt;'s injection constructor, passing it the instance of &lt;span class="codeInline"&gt;Sword&lt;/span&gt; as an argument.&lt;/li&gt;
&lt;li&gt;(1) The kernel returns the newly-created instance of &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; to the site of the method call in &lt;span class="codeInline"&gt;Main()&lt;/span&gt;.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Whew! After all that, we end up with a &lt;span class="codeInline"&gt;Samurai&lt;/span&gt; armed with a &lt;span class="codeInline"&gt;Sword&lt;/span&gt;, and the call to its &lt;span class="codeInline"&gt;Attack()&lt;/span&gt; method results in the same output as our original example: &lt;i&gt;Chopped the evildoers clean in half&lt;/i&gt;. Although this might look like a lot of work just to get the same outcome, keep a few things in mind:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;All of this happens in the background, and you rarely have to think about what's really happening. It Just Works.&lt;/li&gt;
&lt;li&gt;It actually adds much less overhead than it seems. Honest. :)&lt;/li&gt;
&lt;li&gt;This is an overly simplistic example. The more complex your application becomes, the more the power of Ninject will appear.&lt;/li&gt;&lt;/ol&gt;
&lt;br /&gt;Continue reading: &lt;a href="http://ninject.codeplex.com/Wiki/View.aspx?title=How%20Injection%20Works&amp;referringTitle=Home"&gt;How Injection Works&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>NotMyself</author><pubDate>Mon, 12 Oct 2009 15:26:32 GMT</pubDate><guid isPermaLink="false">Updated Wiki: The Activation Process 20091012032632P</guid></item><item><title>Updated Wiki: Providers and the Activation Context</title><link>http://ninject.codeplex.com/Wiki/View.aspx?title=Providers and the Activation Context&amp;version=2</link><description>&lt;div class="wikidoc"&gt;Okay, so remember when we said type bindings were from a service type to an implementation type? Well, we lied. You caught us. Type binding is really a little bit more complicated than we let on. Rather than being from one type to another, bindings are actually from a service type to a &lt;i&gt;provider&lt;/i&gt;. Simply put, a provider is an object that can create instances of another type. It's like a factory, but specifically designed to work with Ninject.&lt;br /&gt;&lt;br /&gt;When you define a binding from a service type to an implementation type, like the binding from &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt; to &lt;span class="codeInline"&gt;Sword&lt;/span&gt; in the previous example, you're really declaring a binding from &lt;span class="codeInline"&gt;IWeapon&lt;/span&gt; to a special built-in provider called &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt;. This &lt;span class="codeInline"&gt;StandardProvider&lt;/span&gt; is like a &amp;quot;super-factory&amp;quot;, in that it can create instances of all sorts of types. It also understands how to resolve the arguments to inject into constructors.&lt;br /&gt;&lt;br /&gt;All of this stuff happens behind the scenes, though, and you rarely need to worry about it. However, sometimes you might want to do some sort of complex custom initialization to your objects, rather than letting Ninject work its magic. If you need to (or if you're just a control freak!), you can create your own provider and bind directly to it:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Bind&amp;lt;IWeapon&amp;gt;().ToProvider(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; SwordProvider());
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;VB.NET:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Bind(Of IWeapon)().ToProvider(&lt;span style="color:Blue;"&gt;New&lt;/span&gt; SwordProvider())
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Providers just need to implement the &lt;span class="codeInline"&gt;IProvider&lt;/span&gt; interface (in &lt;span class="codeInline"&gt;Ninject.Core.Activation&lt;/span&gt;):&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;interface&lt;/span&gt; IProvider {
  Type Prototype { &lt;span style="color:Blue;"&gt;get&lt;/span&gt;; }
  &lt;span style="color:Blue;"&gt;bool&lt;/span&gt; IsCompatibleWith(Type type);
  Type GetImplementationType(IContext context);
  &lt;span style="color:Blue;"&gt;object&lt;/span&gt; Create(IContext context);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Although this might look kind of complicated, the majority of custom providers don't need to implement the first two bits. The magic really happens in the &lt;span class="codeInline"&gt;Create()&lt;/span&gt; method. To simplify matters, Ninject also has an abstract type called &lt;span class="codeInline"&gt;SimpleProvider&amp;lt;T&amp;gt;&lt;/span&gt; that gives you the basics, and adds in strong-typing as well. Here's what &lt;span class="codeInline"&gt;SimpleProvider&amp;lt;T&amp;gt;&lt;/span&gt; looks like:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;abstract&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; SimpleProvider&amp;lt;T&amp;gt; {
  &lt;span style="color:Green;"&gt;// Simple implementations of the junk that you don't care about...&lt;/span&gt;

  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;object&lt;/span&gt; Create(IContext context) {
    &lt;span style="color:Blue;"&gt;return&lt;/span&gt; CreateInstance(context);
  }

  &lt;span style="color:Blue;"&gt;protected&lt;/span&gt; &lt;span style="color:Blue;"&gt;abstract&lt;/span&gt; T CreateInstance(IContext context);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;By using &lt;span class="codeInline"&gt;SimpleProvider&amp;lt;T&amp;gt;&lt;/span&gt;, custom providers just need to override the &lt;span class="codeInline"&gt;CreateInstance()&lt;/span&gt; method. Here's an example of a simple provider for our &lt;span class="codeInline"&gt;Sword&lt;/span&gt; class:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C#:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;class&lt;/span&gt; SwordProvider : SimpleProvider&amp;lt;Sword&amp;gt; {
  &lt;span style="color:Blue;"&gt;protected&lt;/span&gt; &lt;span style="color:Blue;"&gt;override&lt;/span&gt; Sword CreateInstance(IContext context) {
    Sword sword = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Sword();
    &lt;span style="color:Green;"&gt;// Do some complex initialization here.&lt;/span&gt;
    &lt;span style="color:Blue;"&gt;return&lt;/span&gt; sword;
  }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;VB.NET:&lt;/b&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;Public&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt; SwordProvider
  &lt;span style="color:Blue;"&gt;Inherits&lt;/span&gt; SimpleProvider(Of Sword)
  &lt;span style="color:Blue;"&gt;Protected&lt;/span&gt; &lt;span style="color:Blue;"&gt;Overrides&lt;/span&gt; &lt;span style="color:Blue;"&gt;Function&lt;/span&gt; Sword CreateInstance(context &lt;span style="color:Blue;"&gt;as&lt;/span&gt; IContext)
    &lt;span style="color:Blue;"&gt;Dim&lt;/span&gt; sword &lt;span style="color:Blue;"&gt;As&lt;/span&gt; &lt;span style="color:Blue;"&gt;New&lt;/span&gt; Sword()
    &lt;span style="color:Green;"&gt;'Do some complex initialization here.&lt;/span&gt;
    &lt;span style="color:Blue;"&gt;Return&lt;/span&gt; Sword
  &lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Function&lt;/span&gt;
&lt;span style="color:Blue;"&gt;End&lt;/span&gt; &lt;span style="color:Blue;"&gt;Class&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This brings up another hidden complexity in Ninject, the context. See, Ninject is pretty smart. When it's resolving a big complex graph of objects, it keeps track of where it is, what's being injected, who's asking for it, etc. All of this information is stored in the context, represented by the &lt;span class="codeInline"&gt;IContext&lt;/span&gt; interface. If you need it, your provider can access all of this information to make decisions about how to resolve the dependencies. If you don't need it (like in the &lt;span class="codeInline"&gt;SwordProvider&lt;/span&gt; above), you can just ignore it.&lt;br /&gt;&lt;br /&gt;Each time an instance is resolved, a new child context is created and the kernel's &lt;span class="codeInline"&gt;Get()&lt;/span&gt; is called again. Through this (somewhat) recursive operation, Ninject forms a stack of activation contexts, all of which are available throughout the system during the activation process.&lt;br /&gt;&lt;br /&gt;Continue reading: &lt;a href="http://ninject.codeplex.com/Wiki/View.aspx?title=The%20Activation%20Process&amp;referringTitle=Home"&gt;The Activation Process&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>NotMyself</author><pubDate>Mon, 12 Oct 2009 15:24:24 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Providers and the Activation Context 20091012032424P</guid></item></channel></rss>