Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the book "Dependency Injection in .NET" by Mark Seemann, in chapter 2 he talks about 4 different patterns of injection:</p> <ol> <li>Constructor Injection</li> <li>Property Injection</li> <li>Method Injection</li> <li>Ambient Context</li> </ol> <p>The 4th one, Ambient Context, is a static property, which can be of an abstract type. This property can be set in the DI Root, thread context, call context, request context, etc. .NET Security, Transactions and other stuff like that use this pattern.</p> <p>Here are links that will give you more details:<br/></p> <ul> <li><a href="http://aabs.wordpress.com/2007/12/31/the-ambient-context-design-pattern-in-net/" rel="nofollow">"The Ambient Context Design Pattern in .NET"</a> by The Wandering Glitch</li> <li><a href="http://blogs.msdn.com/b/ploeh/archive/2007/07/23/ambientcontext.aspx" rel="nofollow">"Ambient Context"</a> by Mark Seemann<br/></li> <li><a href="http://www.timjroberts.com/2010/12/the-ambient-context-pattern/" rel="nofollow">"The Ambient Context Pattern"</a> by Tim Robert</li> </ul> <p>Here is some sample code:</p> <pre class="lang-cs prettyprint-override"><code>public interface IOutput { void Print(Person person); } public class ConsoleOutput : IOutput { public void Print(Person person) { Console.WriteLine("{0} {1}", person.FirstName, person.LastName); } } public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public static class SampleContext { public static IOutput Output { get; set; } } public static class ExtensionMethods { public static void Print(this Person person) { SampleContext.Output.Print(person); } } static class Program { static void Main() { //You would use your DI framework here SampleContext.Output = new ConsoleOutput(); //Then call the extension method var person = new Person() { FirstName = "Louis-Pierre", LastName = "Beaumont" }; person.Print(); } } </code></pre>
    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. VO
      singulars
      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