<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>maonet technotes &#187; StructureMap</title>
	<atom:link href="http://maonet.wordpress.com/category/structuremap/feed/" rel="self" type="application/rss+xml" />
	<link>http://maonet.wordpress.com</link>
	<description>IOC(SM):MOC(RM):TDD(NU):SCC(TFS):ORM(L2S):JSL(Jq):CIS(CC)</description>
	<lastBuildDate>Thu, 31 Dec 2009 17:16:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='maonet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/27569a47b055d3d0ff1d52cf3b0ce0d7?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>maonet technotes &#187; StructureMap</title>
		<link>http://maonet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://maonet.wordpress.com/osd.xml" title="maonet technotes" />
		<item>
		<title>Control the entry point of WPF application</title>
		<link>http://maonet.wordpress.com/2009/05/07/control-the-entry-point-of-wpf-application/</link>
		<comments>http://maonet.wordpress.com/2009/05/07/control-the-entry-point-of-wpf-application/#comments</comments>
		<pubDate>Thu, 07 May 2009 15:05:18 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[StructureMap]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=590</guid>
		<description><![CDATA[The app.main() is gone in default auto-gened WPF application, there are some workarounds to add customized startup app class. I found adding Startup attribute then implement startup eventhandler is a eaiser and clean solution:
Adding Startup property to App.xaml:

&#60;Application x:Class=&#8221;StakeholderDemo.Layers.WpfUI.App&#8221;
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8220;
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8220;
Startup=&#8221;App_StartUp&#8221;
StartupUri=&#8221;MenuForm.xaml&#8221;
&#62;
&#60;Application.Resources&#62;
&#60;/Application.Resources&#62;
&#60;/Application&#62;

Implement code:

public partial class App : Application
{
void  App_StartUp(object sender, StartupEventArgs e)
{
ObjectFactory.Initialize(x =&#62;  x.AddRegistry&#60;WpfClientDependencyRegistry&#62;());
}

   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=590&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The app.main() is gone in default auto-gened WPF application, there are <a href="http://www.infosysblogs.com/microsoft/2008/09/how_to_write_custom_main_metho.html">some workarounds</a> to add customized startup app class. I found adding Startup attribute then implement startup eventhandler is a eaiser and clean solution:</p>
<div>Adding Startup property to App.xaml:</div>
<blockquote>
<div>&lt;Application x:Class=&#8221;StakeholderDemo.Layers.WpfUI.App&#8221;<br />
xmlns=&#8221;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>&#8220;<br />
xmlns:x=&#8221;<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>&#8220;<br />
<span style="color:#ff0000;">Startup=&#8221;App_StartUp&#8221;</span><br />
StartupUri=&#8221;MenuForm.xaml&#8221;<br />
&gt;<br />
&lt;Application.Resources&gt;</p>
<p>&lt;/Application.Resources&gt;<br />
&lt;/Application&gt;</p></div>
</blockquote>
<div>Implement code:</div>
<blockquote>
<div>public partial class App : Application<br />
{</p>
<p>void  App_StartUp(object sender, StartupEventArgs e)<br />
{<br />
ObjectFactory.Initialize(x =&gt;  x.AddRegistry&lt;WpfClientDependencyRegistry&gt;());<br />
}</p></div>
</blockquote>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/590/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=590&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2009/05/07/control-the-entry-point-of-wpf-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Auto-wiring in StructureMap 2.5</title>
		<link>http://maonet.wordpress.com/2008/11/19/auto-wire-in-structuremap-25/</link>
		<comments>http://maonet.wordpress.com/2008/11/19/auto-wire-in-structuremap-25/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 16:37:11 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[StructureMap]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=297</guid>
		<description><![CDATA[While I was confused by other posts mentioning LookForRegistries() by scan assembly, Derik Whittaker&#8217;s post explained how to do auto-wire in SC2.5, that&#8217;s just what I want! But I couldn&#8217;t move this code into a Registry class. Meanwhile I saw Jeremy Miller kept saying:
Don&#8217;t ever make any calls to ObjectFactory within a Registry.
I&#8217;m not sure [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=297&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>While I was confused by other posts mentioning LookForRegistries() by scan assembly, <a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/10/13/setup-up-structuremap-2-5-to-auto-configure-your-dependencies.aspx?CommentPosted=true#commentmessage">Derik Whittaker&#8217;s post </a>explained how to do auto-wire in SC2.5, that&#8217;s just what I want! But I couldn&#8217;t move this code into a Registry class. Meanwhile I saw <a href="http://groups.google.com/group/structuremap-users/browse_thread/thread/1e78a226a4652bac/42a1f3c75bdf1c07?hl=en&amp;lnk=gst&amp;q=scan+assembly#42a1f3c75bdf1c07">Jeremy Miller kept saying</a>:</p>
<blockquote><p>Don&#8217;t ever make any calls to ObjectFactory within a Registry.</p></blockquote>
<p>I&#8217;m not sure does this mean I am not supposed to do OBjectFactory.Configure() in my Registry. If no, how can I refactor this code?</p>
<pre class="brush: csharp;">
        private static void SetupStructureMap()
        {
            ObjectFactory.Initialize(
                x=&gt;
                    {
                        // &lt;a href=&quot;http://codebetter.com/blogs/jeremy.miller/archive/2008/10/25/initializing-and-configuring-a-structuremap-container.aspx&quot;&gt;Ingore config file&lt;/a&gt;
                        x.UseDefaultStructureMapConfigFile = false

                        x.AddRegistry&lt;AuthorizationRegistry&gt;();
                        x.AddRegistry&lt;RepositoriesRegistry&gt;(); 

                        x.Scan(scanner =&gt;
                         {
                             scanner.Assembly(&quot;Aglc.Stakeholder.Data.LINQ&quot;);
                             scanner.WithDefaultConventions();
                         });

                    });
        }
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/297/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=297&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/11/19/auto-wire-in-structuremap-25/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>StructureMap Registry in WCF</title>
		<link>http://maonet.wordpress.com/2008/09/05/structuremap-registry-in-wcf/</link>
		<comments>http://maonet.wordpress.com/2008/09/05/structuremap-registry-in-wcf/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 20:02:05 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[StructureMap]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=214</guid>
		<description><![CDATA[Following the post by Jimmy Bogard,  with Oran&#8217;s example, I figured this out finally. So I can remove the xml config file for both winForm and WCFHost.
I was wondering how to do the similar process in WCF just like appStart in WinForm, even it was so complicated, but it&#8217;s feasible, by implementing my own wcf [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=214&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Following the <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/07/29/integrating-structuremap-with-wcf.aspx">post by Jimmy Bogard</a>,  with <a href="http://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html">Oran&#8217;s example</a>, I figured this out finally. So I can remove the xml config file for both winForm and WCFHost.</p>
<p>I was wondering how to do the similar process in WCF just like appStart in WinForm, even it was so complicated, but it&#8217;s feasible, by implementing my own wcf service Factory.</p>
<p>It works with CSLA just like a charm. The only thing you should keep in mind is, in unit-test, still use ObjectFactory.Inject(). Don&#8217;t try to touch registry unitll you want to test registry configuration itself.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/214/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/214/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=214&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/09/05/structuremap-registry-in-wcf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Replace file content in NAnt task</title>
		<link>http://maonet.wordpress.com/2008/08/12/replace-file-content-in-nant-task/</link>
		<comments>http://maonet.wordpress.com/2008/08/12/replace-file-content-in-nant-task/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 17:48:42 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[NAnt]]></category>
		<category><![CDATA[StructureMap]]></category>
		<category><![CDATA[cruisecontrol]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=182</guid>
		<description><![CDATA[As JP suggested, I always compile all my layered projects into a huge dll to make NAnt build file eaiser. This solution is perfect until I tried to embeb structuremap config file into cruise control. Because assembly file name changed, I have to find a way to replace the config file content in NAnt.
It was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=182&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As JP suggested, I always compile all my layered projects into a huge dll to make NAnt build file eaiser. This solution is perfect until I tried to embeb structuremap config file into cruise control. Because assembly file name changed, I have to find a way to replace the config file content in NAnt.</p>
<p>It was not easy. NAnt doesn&#8217;t have a replace task!</p>
<p>I don&#8217;t want hack into NAnt source to re-build my own version. It seems Jay Flowers, the creator of CI Factory has <a href="http://jayflowers.com/joomla/index.php?option=com_content&amp;task=view&amp;id=24&amp;Itemid=51">his modified version of NAnt</a> which has replace task in it, but, no document to direct me how to use it.</p>
<p>OK, I have to call Ant task in NAnt build file then.</p>
<blockquote><p>[NAnt build file]<br />
&lt;exec program=&#8221;c:\ant\bin\ant.bat&#8221; basedir=&#8221;${base.dir} &#8220;&gt;<br />
&lt;arg value=&#8221;-Dcurrentproject.lib=${currentproject.lib}&#8221; /&gt;<br />
&lt;/exec&gt;</p></blockquote>
<blockquote><p>[Ant file]<br />
&lt;project name=&#8221;config&#8221; default=&#8221;replace_config&#8221; basedir=&#8221;.&#8221;&gt;</p>
<p>&lt;property name=&#8221;build.dir&#8221; value=&#8221;${basedir}\build&#8221;/&gt;<br />
&lt;property name=&#8221;currentproject.lib&#8221; value=&#8221;undefined&#8221;/&gt;</p>
<p>&lt;target name=&#8221;replace_config&#8221;&gt;<br />
&lt;replace file=&#8221;${build.dir}\StructureMap.config&#8221;&gt;<br />
&lt;replacefilter token=&#8221;,mybizlayer&#8221; value=&#8221;,${currentproject.lib}&#8221;  /&gt;<br />
&lt;replacefilter token=&#8221;,mydatalayer&#8221; value=&#8221;,${currentproject.lib}&#8221;  /&gt;</p>
<p>&lt;/replace&gt;</p>
<p>&lt;/target&gt;<br />
&lt;/project&gt;</p></blockquote>
<blockquote></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/182/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/182/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=182&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/08/12/replace-file-content-in-nant-task/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
		<item>
		<title>Using StructureMap to mock DataAccess in CSLA BO</title>
		<link>http://maonet.wordpress.com/2008/08/08/using-structuremap-to-mock-dataaccess-in-csla-bo/</link>
		<comments>http://maonet.wordpress.com/2008/08/08/using-structuremap-to-mock-dataaccess-in-csla-bo/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 15:19:17 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[CSLA]]></category>
		<category><![CDATA[IOC]]></category>
		<category><![CDATA[MoQ]]></category>
		<category><![CDATA[StructureMap]]></category>
		<category><![CDATA[TypeMock]]></category>
		<category><![CDATA[mock]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/?p=174</guid>
		<description><![CDATA[I had always thought StructureMap is just another IOC tool similar to Castle windsor, until yesterday I read Karl Seguin&#8217;s Foundations of Programming, Chapter 4, I was shocked immediately by the injectStub method provided by StructureMap, which is now renamed to inject(). I think this explicitly injection is better than TypeMock implicitly mock instance object.
For [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=174&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I had always thought StructureMap is just another IOC tool similar to Castle windsor, until yesterday I read Karl Seguin&#8217;s <em>Foundations of Programming, </em>Chapter 4, I was shocked immediately by the injectStub method provided by StructureMap, which is now renamed to inject(). I think this explicitly injection is better than <a href="http://maonet.wordpress.com/2008/05/06/typemock-repository-object-in-csla-bo/">TypeMock implicitly mock instance object</a>.</p>
<p>For example, I have an Organization BO,</p>
<pre class="brush: csharp;">

public static OrganizationBO GetOrganizationBO(int Id)
{
return DataPortal.Fetch&lt;OrganizationBO&gt;(new SingleCriteria&lt;OrganizationBO, int&gt;(Id));
}

private void DataPortal_Fetch(SingleCriteria&lt;OrganizationBO, int&gt; criteria)
{
OrganizationDTO data = DataAccess.OrganizationRepository().FindById(criteria.Value);

if (data != null)
{
LoadFromDTO(data);
}
}
</pre>
<p>The repository is declared in DataAccess class to centralize all the dataaccess coupling inside CALS BOs.</p>
<pre class="brush: csharp;">

public static IRepository&lt;OrganizationDTO&gt; OrganizationRepository()
{

// instead of direct coupling return new OrganizationRepository();
// I use StrcutureMap
return ObjectFactory.GetInstance&lt;IRepository&lt;OrganizationDTO&gt;&gt;();
}
</pre>
<p>The content of IOC config file:</p>
<blockquote><p>&lt;DefaultInstance<br />
PluginType=&#8221;DemoApp.Data.Interfaces.IRepository`1,DemoApp.Data&#8221;    PluggedType=&#8221;DemoApp.Data.Repository.OrganizationRepository,DemoApp.Data&#8221;<br />
/&gt;</p></blockquote>
<p>We can also use other different ways to set dependency, like setDefault in code, or search assembly at  runtime as <a href="http://codebucket.org/archive/2008/08/10/three-ways-to-register-dependencies-with-structuremap-2.4.9.aspx">shown in this post</a>.</p>
<p>Test  code:</p>
<pre class="brush: csharp;">

[Test]
public void CanGetFromInjectedMockRepository()
{
var mockRepository = new Moq.Mock&lt;IRepository&lt;OrganizationDTO&gt;&gt;();

// Id in MoQ matters. But TypeMock doesn't care.
mockRepository.Expect(x =&gt; x.FindById(8172)).Returns(
new OrganizationDTO
{
Id = 1,
Name = &quot;A test org name&quot;
});

ObjectFactory.Inject(typeof(IRepository&lt;OrganizationDTO&gt;), mockRepository.Object);

var o = OrganizationBO.GetOrganizationBO(8172);

Assert.AreEqual(1, o.Id);
Assert.AreEqual(&quot;A test org name&quot;, o.Name);
}
</pre>
<p>Here is an artile introducing StructureMap, as it mentioned, StrucutreMap is very good choice if you are working on a class has no &#8220;constructor injection&#8221;, CSLA is one of those!</p>
<p>I have the same feeling, as the author <a href="http://dotnetslackers.com/community/members/kseg.aspx">Karl Seguin</a> said, constructor injection doesn&#8217;t really solve the extensibility problem; how does someone add(try to replace) a new plug-in without recompiling the entire application?</p>
<p>The problem/drawback to DI is also obvious, the xml config file keeps growing and expanding. The performance and mantiance will become an issue. That&#8217;s why Boo was inverted to save / speed up Castle Windsor. But what about structure Map?</p>
<p>Also I need tool / method to test this xml config file, see details <a href="http://structuremap.sourceforge.net/structuremap.verification.htm">here</a> and <a href="http://codebetter.com/blogs/jeremy.miller/archive/2006/04/06/142431.aspx">here</a>. Unfortunately, I couldn&#8217;t make this &lt;structuremap.verification&gt; task loaded into NAnt, (maybe this doesn&#8217;t exist in those two dlls at all? I can&#8217;t tell because NAnt loadTask doesn&#8217;t have output). I tried to different folders and also &#8220;Forced scan&#8221; using &lt;loadtasks&gt; command, neither one works. Thanks God, Jeremy does have another way to test config file,so called smock test:</p>
<blockquote><p>ObjectFactory.AssertConfigurationIsValid();</p></blockquote>
<p>Regarding unit-test and mock, I spent a lot time trying to figure out how to reset the default back. It turns out the documented <a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/07/30/structuremap-change-to-objectfactory-resetdefaults.aspx">ObjectFactory.resetdefault has been changed to reset</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/174/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/174/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/174/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=174&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2008/08/08/using-structuremap-to-mock-dataaccess-in-csla-bo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
	</channel>
</rss>