<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>.NET Meanderings</title>
  <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/" />
  <link rel="self" href="http://www.dotnetconsult.co.uk/weblog2/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2012-01-17T09:18:38.0675000+01:00</updated>
  <author>
    <name>Richard Blewett</name>
  </author>
  <subtitle>Richard Blewett's wanderings around .NET</subtitle>
  <id>http://www.dotnetconsult.co.uk/weblog2/</id>
  <generator uri="http://www.dasblog.net" version="1.9.6264.0">DasBlog</generator>
  <entry>
    <title>DevelopMentor Moorgate Office Launch</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,c45cebe0-f3b4-4c0b-8f98-0c31a068a17b.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,c45cebe0-f3b4-4c0b-8f98-0c31a068a17b.aspx</id>
    <published>2012-01-17T09:18:38.0675000+01:00</published>
    <updated>2012-01-17T09:18:38.0675000+01:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
To celebrate <a href="http://www.develop.com/">DevelopMentor’s</a> move to offices
at 120 Moorgate in London, myself and <a href="http://www.rocksolidknowledge.com/Blog.mvc/ViewBlog?blogName=Andy%20Clymer">Andy
Clymer</a> are presenting an evening of C# 5 Async. The next version of the C# language
has built-in support for async processing. We’ll show you how it improves over the
previous models and how it works under the covers.
</p>
        <p>
This event is on Monday the 6th February from 5-7 and is free to attend, just register
with the DevelopMentor office on 01242 525 108 or email <a href="mailto:salesuk@develop.com">salesuk@develop.com</a></p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=c45cebe0-f3b4-4c0b-8f98-0c31a068a17b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Demos from Basta 2011</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,a5b8a66a-b880-46eb-b656-e33ce7d78c9b.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,a5b8a66a-b880-46eb-b656-e33ce7d78c9b.aspx</id>
    <published>2011-09-29T00:46:31.7790000+02:00</published>
    <updated>2011-09-29T00:46:31.7790000+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thanks to everyone for attending my sessions on the Reactive Framework and Garbage
Collection at <a href="http://basta.net/">Basta 2011</a>, you can download the demos
here:
</p>
        <p>
          <a href="http://rocksolidknowledge.blob.core.windows.net/demos/Basta2011Rx.zip">Reactive
Framework</a>
        </p>
        <p>
          <a href="http://rocksolidknowledge.blob.core.windows.net/demos/Basta2011GC.zip">Garbage
Collection</a>
        </p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=a5b8a66a-b880-46eb-b656-e33ce7d78c9b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Self Hosted Web API / Nuget Gotcha</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,d69307a4-76c2-4a38-b317-1c15fb189acc.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,d69307a4-76c2-4a38-b317-1c15fb189acc.aspx</id>
    <published>2011-06-15T11:21:33.5306250+02:00</published>
    <updated>2011-06-15T11:21:33.5306250+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="REST" label="REST" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,REST.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just a heads up that when self hosting the new WCF Web API. By default if you try
to add the Web API references via Nuget you will get a failure (E_FAIL returned from
a COM component).
</p>
        <p>
This is due to the likely project types (Console, Windows Service, WPF) defaulting
to the client profile rather than the full framework. If you change the project to
the full framework the Nuget packages install correctly
</p>
        <p>
Yet again bitten by the Client Profile 
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=d69307a4-76c2-4a38-b317-1c15fb189acc" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WCF Instances and Threading</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,1efac821-2b89-47bb-9d27-48f0d6347914.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,1efac821-2b89-47bb-9d27-48f0d6347914.aspx</id>
    <published>2011-02-04T22:50:40.3965000+01:00</published>
    <updated>2011-02-05T08:32:59.3652500+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have just found myself answering essentially the same question 4 times on the MSDN
WCF Forum about how instances, threading and throttling interact in WCF. So to save
myself some typing I will walk through the relationships here and then I can reference
this post in questions.
</p>
        <p>
          <strong>Instancing<br /></strong>WCF has 3 built in instancing models: PerCall, PerSession and Single. They
are set on the InstanceContextMode on the ServiceBehavior attribute on the service
implementation. They relate to how many instances of the service implementation class
get used when requests come in, and work as follows:
</p>
        <ul>
          <li>
Single – one instance of the implementation class is used for all requests 
</li>
          <li>
PerCall – every request gets its own instance of the implementation class 
</li>
          <li>
PerSession – this is the slightly odd one as it means every session gets its own instance.
In practical terms it means that for <a href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,af6e6325-2e30-42e3-acb9-57e1363fa51e.aspx">Session</a> supporting
bindings: NetTcpBinding, WSHttpBinding, NetNamedPipeBinding, etc, every proxy gets
an instance of the service. For bindings that do not support session: BasicHttpBinding,
WebHttpBinding, we get the same effect as PerCall. To add to the confusion, this setting
is the default</li>
        </ul>
        <p>
          <strong>Concurrency<br /></strong>By default WCF assumes you do not understand multithreading. Therefore, it
only allows one thread at a time into an instance of the service implementation class
unless you tell it otherwise. You can control this behavior using the ConcurrencyMode
on the ServiceBehavior; it has 3 values:
</p>
        <ul>
          <li>
Single – this is the default and only one thread can get into an instance at a time 
</li>
          <li>
Multiple – any thread can enter an instance at any time 
</li>
          <li>
Reentrant – only makes a difference in <a href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,b891610a-6b78-4b54-b9a6-4ec81c82b7c0.aspx">duplex</a> services
but means that an inbound request can be received from the component you are currently
making a request to (sounds a bit vague but in duplex the role of service and client
are somewhat arbitrary)</li>
        </ul>
        <p>
          <strong>Interaction<br /></strong>Now these two concepts are different but have some level of interaction. 
</p>
        <p>
If you set InstanceContextMode to Single and ConcurrencyMode to Single then your service
will process exactly one request at a time. If you set InstanceContextMode to Single
and ConcurrencyMode to Multiple then your service processes many requests but you
are responsible for ensuring your code is threadsafe.
</p>
        <p>
If you set InstanceContextMode to PerCall then ConcurrencyMode Single and Multiple
behave the same as each request gets its own instance
</p>
        <p>
For PerSession ConcurrencyMode Multiple is only required if you want to support a
client sending multiple requests through the same proxy from multiple threads concurrently
</p>
        <p>
          <strong>Threading<br /></strong>Unless you turn on ASP.NET Compatibility, WCF calls are processed on IO threads
in the system threadpool. There is no thread affinity so any of these threads could
process a request. The number of threads being used will grow until the throughput
of the service matches the number of concurrent requests (assuming the server machine
has the resources to match the number of concurrent requests). Although the number
of IO threads is capped at 1000 by default, if you hit this many then unless you are
running on some big iron hardware you probably have problems in your architecture.
</p>
        <p>
          <strong>Throttling<br /></strong>Throttling is there to ensure your service is not swamped in terms of resources.
There are three throttles in place:
</p>
        <ul>
          <li>
MaxConcurrentCalls – the number of concurrent calls that can be made – under .NET
4 defaults to 16 x number of cores 
</li>
          <li>
MaxConcurrentSessions – the number of concurrent sessions that can be in in flight
– under .NET 4 defaults to 100 x number of cores 
</li>
          <li>
MaxConcurrentObjects – the number of service implementation objects that are in use
– defaults to the sum of MaxConcurrentCalls + MaxConcurrentSessions</li>
        </ul>
        <p>
In reality, depending on whether you are using sessions or not, the session or call
throttle will affect your service the most. The object one will only affect your service
if you set it lower than the others or you do something unsual and handle the mapping
of requests to objects yourself using a custom IInstanceContextProvider
</p>
        <p>
You can control the throttle values using the serviceThrottling service behavior which
you set in the config file or in code
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=1efac821-2b89-47bb-9d27-48f0d6347914" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Software Architect Conference 2010</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,0cf7f2c1-78f5-43d6-820d-849d5cd5fee0.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,0cf7f2c1-78f5-43d6-820d-849d5cd5fee0.aspx</id>
    <published>2010-06-08T11:52:40.7317500+02:00</published>
    <updated>2010-06-08T11:52:40.7317500+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="PFx" label="PFx" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,PFx.aspx" />
    <category term="RSK" label="RSK" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,RSK.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <category term="WF" label="WF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF.aspx" />
    <category term="WF4" label="WF4" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF4.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.dotnetconsult.co.uk/weblog2/content/binary/WindowsLiveWriter/SoftwareArchitectConference2010_98EF/Speaker_SA2010_120x120_4.jpg">
            <img style="border-right-width: 0px; margin: 0px 15px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Speaker_SA2010_120x120" border="0" alt="Speaker_SA2010_120x120" align="left" src="http://www.dotnetconsult.co.uk/weblog2/content/binary/WindowsLiveWriter/SoftwareArchitectConference2010_98EF/Speaker_SA2010_120x120_thumb_1.jpg" width="124" height="124" />
          </a>
        </p>
        <p>
I’m speaking at Software Architect 2010 in October. I’m going to be delivering two
sessions on Windows Workflow Foundation 4.0: the first explains the basic architecture
and looks at using workflow as a Visual Scripting environment to empower business
users. The second looks at building big systems with workflow concentrating on the
WCF integration features. 
</p>
        <p>
In addition to that I’ll be delivering two all-day workshops with <a href="http://andyclymer.blogspot.com/">Andy
Clymer</a>: Building Applications the .NET 4.0 Way and Moving to the Parallel Mindset
with .NET 4.0. The first of these will take a number of new features of .NET 4.0 and
show how they can be combined to create compelling applications. The second will look
at the Parallel Framework Extensions (PFx) introduced in .NET 4.0 examining both the
rich functionality of the library, how it can be best leveraged avoiding common parallel
pitfalls and finally looking at patterns that aid parallelisation of your code
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=0cf7f2c1-78f5-43d6-820d-849d5cd5fee0" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Unity, Multiple Constructors and Configuration</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,adb974bc-7595-4e06-827b-12f7c09208ae.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,adb974bc-7595-4e06-827b-12f7c09208ae.aspx</id>
    <published>2010-06-08T00:14:26.9973750+02:00</published>
    <updated>2010-06-08T00:14:26.9973750+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="IoC" label="IoC" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,IoC.aspx" />
    <category term="Unit Testing" label="Unit Testing" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,Unit%2BTesting.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve been working with the <a href="http://unity.codeplex.com/wikipage?title=Unity2">Unity
IoC container</a> from Microsoft Patterns and Practices recently. Its mostly straightforward
as IoC containers go but one thing had me puzzled for a while as its not really documented
or blogged as far as I can see; so I decided to blog it so hopefully others looking
will stumble across this article
</p>
        <p>
Lets start off with a simple example: I have two interfaces: <font face="Consolas">IService</font> and <font face="Consolas">IRepository</font> that
live in the Interfaces class library
</p>
        <div id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum1"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">interface</span> IService</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum2"> 2:</span> {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum3"> 3:</span>
              <span style="color: #0000ff">void</span> DoWork();</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum4"> 4:</span> }</pre>
            <!--CRLF-->
          </div>
        </div>
        <div id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum1"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">interface</span> IRepository</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum2"> 2:</span> {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum3"> 3:</span>
              <span style="color: #0000ff">string</span> GetStuff();</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum4"> 4:</span> }</pre>
            <!--CRLF-->
          </div>
        </div>
I also have two implementations in the Services class library: <font face="Consolas">MyRepository</font>  
<div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> MyRepository
: IRepository</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> GetStuff()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span><span style="color: #0000ff">return</span><span style="color: #006080">"TADA!!"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> }</pre><!--CRLF--></div></div><p></p><p></p><p></p><p>
and <font face="Consolas">MyService</font></p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> MyService
: IService</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">private</span> IRepository
repository;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span><span style="color: #0000ff">public</span> MyService(IRepository
repository)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span><span style="color: #0000ff">this</span>.repository
= repository;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> DoWork()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> Console.WriteLine(repository.GetStuff());</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> }</pre><!--CRLF--></div></div><p></p><p>
Notice that <font face="Consolas">MyService</font> needs an <font face="Consolas">IRepository</font> to
do its work. Now the idea here is I’m going to wire this together via dependency injection
and the Unity IoC container. So I have my application
</p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">class</span> Program</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">static</span><span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> UnityContainer
container = <span style="color: #0000ff">new</span> UnityContainer();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> UnityConfigurationSection
section = (UnityConfigurationSection)ConfigurationManager.GetSection(<span style="color: #006080">"unity"</span>);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> section.Configure(container);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> IService
svc = container.Resolve&lt;IService&gt;();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> svc.DoWork();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> }</pre><!--CRLF--></div></div><p></p><p>
Notice as we’re using IoC that there are no hard coded dependencies – everything is
wired up via the container. However, there must be some information about how the
interfaces map to concrete types and this is in the config file
</p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="unity"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">unity</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAliases</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span><span style="color: #008000">&lt;!--
Lifetime Managers --&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAlias</span><span style="color: #ff0000">alias</span><span style="color: #0000ff">="singleton"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Microsoft.Practices.Unity.ContainerControlledLifetimeManager"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span><span style="color: #008000">&lt;!--
Interfaces --&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAlias</span><span style="color: #ff0000">alias</span><span style="color: #0000ff">="IService"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Interfaces.IService,Interfaces"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAlias</span><span style="color: #ff0000">alias</span><span style="color: #0000ff">="IRepository"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Interfaces.IRepository,Interfaces"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span><span style="color: #008000">&lt;!--
Implementations --&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAlias</span><span style="color: #ff0000">alias</span><span style="color: #0000ff">="service"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Services.MyService,
Services"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">typeAlias</span><span style="color: #ff0000">alias</span><span style="color: #0000ff">="repository"</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="Services.MyRepository,
Services"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">typeAliases</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20"> 20:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">containers</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21"> 21:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">container</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22"> 22:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">types</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23"> 23:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">type</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="IService"</span><span style="color: #ff0000">mapTo</span><span style="color: #0000ff">="service"</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24"> 24:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">lifetime</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="singleton"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25"> 25:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">type</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26"> 26:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">type</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="IRepository"</span><span style="color: #ff0000">mapTo</span><span style="color: #0000ff">="repository"</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27"> 27:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">lifetime</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="singleton"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28"> 28:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">type</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29"> 29:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">types</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30"> 30:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">container</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31"> 31:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">containers</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32"> 32:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">unity</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33"> 33:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--></div></div><p></p><p>
Now all of this works fine and is simple Unity stuff. We use constructor injection
to get the repository implementation into the service constructor. However, I’ve decided
the service needs a timeout that I will generally configure in the config file. However
to make Unit Testing simple I’ll add another constructor to <font face="Consolas">MyService</font> so
I can pass a specific timeout
</p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> MyService
: IService</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">private</span> IRepository
repository;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> TimeSpan
timeout;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span><span style="color: #0000ff">public</span> MyService(IRepository
repository, TimeSpan timeout)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span><span style="color: #0000ff">this</span>.timeout
= timeout;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span><span style="color: #0000ff">public</span> MyService(IRepository
repository)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span><span style="color: #0000ff">this</span>.repository
= repository;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> timeout
= GetTimeoutFromConfig();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span><span style="color: #0000ff">private</span> TimeSpan
GetTimeoutFromConfig()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span><span style="color: #0000ff">return</span><span style="color: #0000ff">default</span>(TimeSpan);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20"> 20:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21"> 21:</span>  </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22"> 22:</span><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> DoWork()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23"> 23:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24"> 24:</span> Console.WriteLine(repository.GetStuff());</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25"> 25:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26"> 26:</span> }</pre><!--CRLF--></div></div><p></p><p>
Now I try to run the application and I get a pretty ugly error
</p><font size="2" face="Consolas"><font size="2" face="Consolas"><p>
Unhandled Exception: Microsoft.Practices.Unity.ResolutionFailedException: Resolution
of the dependency failed, 
<br />
type = "Interfaces.IService", name = "(none)".<br />
Exception occurred while: while resolving.<br />
Exception is: InvalidOperationException - The type Int32 cannot be constructed.<br />
You must configure the container to supply this value.
</p></font></font><p><font face="Consolas"><font face="Consolas"><font size="2" face="Trebuchet MS">Now
that’s weird – I have no types that take an <font face="Consolas">Int32</font>! This
is caused by Unity’s default behavior where it will try to resolve on the constructor
with the most parameters (on the basis that this one will have the most dependencies
that can be injected). It tried to resolve the <font face="Consolas">TimeSpan</font> and
so looks at the <font face="Consolas">TimeSpan</font> and tries to resolve its constructor
which can take an <font face="Consolas">Int32</font>. I actually want to tell it to
use a different constructor and I can do this in two ways: annotate the constructor
I want to use with the <font face="Consolas">[InjectionConstructor]</font> attribute</font></font></font></p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> [InjectionConstructor]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span><span style="color: #0000ff">public</span> MyService(IRepository
repository)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span><span style="color: #0000ff">this</span>.repository
= repository;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> timeout
= GetTimeoutFromConfig();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> }</pre><!--CRLF--></div></div><font size="2" face="Consolas"><font size="2" face="Consolas"></font></font><p>
But personally I don’t like this. It forces the services assembly to take a dependency
on Unity and the service has knowledge about how its being constructed. What I really
want to do is specify this in config. This isn’t very well documented from what I
can see but what you do it specify the constructor and how to resolve the parameters
against the type mapping in the config – i.e.
</p><div id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">type</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="IService"</span><span style="color: #ff0000">mapTo</span><span style="color: #0000ff">="service"</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">lifetime</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="singleton"</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">constructor</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">param</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="repository"</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">dependency</span><span style="color: #0000ff">/&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">param</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">constructor</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">type</span><span style="color: #0000ff">&gt;</span></pre><!--CRLF--></div></div><p></p>
As well as specifying dependencies you can also give explicit values by using <font face="Consolas">&lt;value/&gt;</font> instead
of <font face="Consolas">&lt;dependency/&gt;</font>. This model I think is a lot cleaner
than the attribute approach.<img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=adb974bc-7595-4e06-827b-12f7c09208ae" /></div>
    </content>
  </entry>
  <entry>
    <title>Windows AppFabric Hits the Streets</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,0542f45a-40cc-4b2c-9bc4-b4b2740b2af4.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,0542f45a-40cc-4b2c-9bc4-b4b2740b2af4.aspx</id>
    <published>2010-06-07T23:05:40.6380000+02:00</published>
    <updated>2010-06-07T23:05:40.6380000+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="Dublin" label="Dublin" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,Dublin.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <category term="WF" label="WF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Announced today at TechEd – Windows AppFabric is now available
</p>
        <p>
          <a href="http://blogs.msdn.com/b/endpoint/archive/2010/06/07/windows-server-appfabric-now-generally-available.aspx">http://blogs.msdn.com/b/endpoint/archive/2010/06/07/windows-server-appfabric-now-generally-available.aspx</a>
        </p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=0542f45a-40cc-4b2c-9bc4-b4b2740b2af4" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Visual Studio 2010 Power Tools</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,c12e0817-7c4b-4d6b-abce-a2afeeb258ce.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,c12e0817-7c4b-4d6b-abce-a2afeeb258ce.aspx</id>
    <published>2010-06-07T21:26:40.1848750+02:00</published>
    <updated>2010-06-07T21:26:40.1848750+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="VS" label="VS" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,VS.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef">Visual
Studio 2010 Power Tools</a> have just been released. There’s all sorts of goodness
in here: new flexible tab handling in the VS shell (vertical tab groups, tabs grouped
by project, dropping of rarely used tabs, etc); a new searchable Add Reference dialog;
new editor enhancements to make navigation easier and much more
</p>
        <p>
I’ve been playing with it for the last couple of hours and its very neat. Of course
I don’t use <a href="http://www.jetbrains.com/resharper/">Resharper</a> or <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush</a> (I
use too many machines I don’t control to become dependent on them) so some of these
features may be available in those tools. But for me the power tools are a welcome
addition to the IDE
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=c12e0817-7c4b-4d6b-abce-a2afeeb258ce" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Rock Solid Knowledge Screencasts now Available via iTunes</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,332e063e-732b-45b7-a04b-2051785e0877.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,332e063e-732b-45b7-a04b-2051785e0877.aspx</id>
    <published>2010-03-30T22:13:22.0127500+02:00</published>
    <updated>2010-03-30T22:13:22.0127500+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="EF4" label="EF4" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,EF4.aspx" />
    <category term="PFx" label="PFx" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,PFx.aspx" />
    <category term="RSK" label="RSK" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,RSK.aspx" />
    <category term="SilverLight" label="SilverLight" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,SilverLight.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <category term="WF" label="WF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF.aspx" />
    <category term="WF4" label="WF4" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF4.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Rock Solid Knowledge on iTunes is live! We’ve taken the feed to our free screencasts
and they are now available through iTunes via the following link
</p>
        <p>
          <a href="http://itunes.apple.com/gb/podcast/rock-solid-knowledge-screencasts/id365244375">http://itunes.apple.com/gb/podcast/rock-solid-knowledge-screencasts/id365244375</a>
        </p>
        <p>
Now you can watch them on the move
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=332e063e-732b-45b7-a04b-2051785e0877" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Demos from DevWeek 2010</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,ab2a4f9a-b925-4903-8792-fb0a3bc3386c.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,ab2a4f9a-b925-4903-8792-fb0a3bc3386c.aspx</id>
    <published>2010-03-17T09:13:59.3012500+01:00</published>
    <updated>2010-03-17T09:13:59.3012500+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="EF4" label="EF4" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,EF4.aspx" />
    <category term="RSK" label="RSK" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,RSK.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <category term="WF" label="WF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF.aspx" />
    <category term="WF4" label="WF4" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WF4.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thanks to everyone who attended my sessions at DevWeek 2010. I’ve now uploaded the
demos which you can find at the following locations
</p>
        <p>
          <a href="http://rocksolidknowledge.blob.core.windows.net/demos/DevWeek2010DayOf4.0.zip">A
Day of .NET 4.0 Demos</a>
        </p>
        <p>
          <a href="http://rocksolidknowledge.blob.core.windows.net/demos/DevWeek2010WF4.zip">Windows
Workflow Foundation 4.0 Demos</a>
        </p>
        <p>
          <a href="http://rocksolidknowledge.blob.core.windows.net/demos/DevWeek2010WFServices.zip">Creating
WCF Services using WF4 Demos</a>
        </p>
        <p>
I’ll be around for the rest of the conference so drop by for a chat at our <a href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,93eeba3c-1dda-4f49-980d-03485fe9572e.aspx">developer
clinic</a> in the exhibition area
</p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=ab2a4f9a-b925-4903-8792-fb0a3bc3386c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Using advanced filters for custom routing logic in the Routing Service</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,cd224eac-11f1-495e-a0f5-6b7678e2f35e.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,cd224eac-11f1-495e-a0f5-6b7678e2f35e.aspx</id>
    <published>2010-03-10T14:05:40.5310000+01:00</published>
    <updated>2010-03-10T14:05:40.5310000+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="RSK" label="RSK" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,RSK.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In <a href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,7e558c12-f091-4c02-99c6-90eeca251641.aspx">my
last post</a> I pointed to a screencast I had recorded that showed how to create a
custom message filter to plug your own logic into the WCF 4.0 Routing Service. However,
the simple custom filter is only the start – you can actually take control of part
of the routing table which allows you to make global decisions about which filters
match a particular request. On that basis I have created another screencast that shows
how to build one of these more complex custom filters. in this case I use the example
of a round robin load balancer where you can use a file on the file system to indicate
whether a specific endpoint should be considered part of the load balancing algorithm
</p>
        <p>
You can find this last in the series of screencasts on the routing service, along
with all the others here, on the <a href="http://rocksolidknowledge.com/">Rock Solid
Knowledge</a> site
</p>
        <p>
          <a href="http://rocksolidknowledge.com/ScreenCasts.mvc">http://rocksolidknowledge.com/ScreenCasts.mvc</a>
        </p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=cd224eac-11f1-495e-a0f5-6b7678e2f35e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Using Custom Message Filters with the Routing Service</title>
    <link rel="alternate" type="text/html" href="http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,7e558c12-f091-4c02-99c6-90eeca251641.aspx" />
    <id>http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,7e558c12-f091-4c02-99c6-90eeca251641.aspx</id>
    <published>2010-03-08T13:37:22.1247500+01:00</published>
    <updated>2010-03-08T13:37:22.1247500+01:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,.NET.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.dotnetconsult.co.uk/weblog2/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve just uploaded a new screencast on the the <a href="http://www.rocksolidknowledge.com/">Rock
Solid Knowledge site</a>. This one shows you how to plug your own routing logic into
the new Routing Service that is part of WCF 4.0. It uses a custom message filter that
can be used to supplement the existing set of filters such as matching on XPath and
Action. 
</p>
        <p>
You can find the screencast (along with the previous ones in the series) here
</p>
        <p>
          <a href="http://www.rocksolidknowledge.com/ScreenCasts.mvc">
            <u>
              <font color="#0066cc">http://www.rocksolidknowledge.com/ScreenCasts.mvc</font>
            </u>
          </a>
        </p>
        <img width="0" height="0" src="http://www.dotnetconsult.co.uk/weblog2/aggbug.ashx?id=7e558c12-f091-4c02-99c6-90eeca251641" />
      </div>
    </content>
  </entry>
</feed>
