<?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/"
	>

<channel>
	<title>amptools &#187; .net</title>
	<atom:link href="http://www.amptools.net/tag/net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.amptools.net</link>
	<description>Simplify your life.</description>
	<lastBuildDate>Sat, 08 May 2010 07:40:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Switching between Ioc libraries in Net.</title>
		<link>http://www.amptools.net/blog/switching-between-ioc-libraries-in-net</link>
		<comments>http://www.amptools.net/blog/switching-between-ioc-libraries-in-net#comments</comments>
		<pubDate>Fri, 23 Oct 2009 01:04:55 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[common-service-locator]]></category>
		<category><![CDATA[dependency-injection]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[inversion-of-control]]></category>
		<category><![CDATA[ioc]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=239</guid>
		<description><![CDATA[Lets face it. Some developers are religiously attached to their beloved languages, frameworks, and libraries.
This becomes a problem when building software with hopes of gaining a developer base.  If it is not built on Unity, Castle Windsor, Structure Map or [insert beloved Ioc library here], they refuse to work/use the software.
Evidently others have had [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>Lets face it. Some developers are religiously attached to their beloved languages, frameworks, and libraries.</p>
<p>This becomes a problem when building software with hopes of gaining a developer base.  If it is not built on Unity, Castle Windsor, Structure Map or [insert beloved Ioc library here], they refuse to work/use the software.</p>
<p>Evidently others have had this issue and have created a solution, the <a href="http://www.codeplex.com/CommonServiceLocator">common service locator</a>. Â I ran across while searching for asp.net Â mvc and DI (dependency injection) for models. More on DI with models inside controllers in a future post.</p>
<h2>How to use</h2>
<p>Download the library from <a href="http://www.codeplex.com/commonservicelocator">codeplex.com/CommonServiceLocator</a></p>
<p>Its pretty straight forward. Â Download the service locator adapter for the Ioc library of your code on the <a href="http://www.codeplex.com/commonservicelocator">codeplex.com/CommonServiceLocator</a></p>
<div class="wp-caption alignnone" style="width: 439px"><img title="common service locator adapters" src="http://farm3.static.flickr.com/2447/4035421289_eb10bffd3b_o.png" alt="choose the adapter for your Ioc library. " width="429" height="265" /><p class="wp-caption-text">choose the adapter for your Ioc library. </p></div>
<p>Configure your Ioc library in the usual manner. Then pass the container into the adapter.</p>
<pre class="brush: csharp;">
        private IServiceLocator CreateLocator()
        {
            var container = new UnityContainer();
            container.RegisterType&lt;IUser, User&gt;();
            container.RegisterType&lt;IMembership, Membership&gt;();
            container.RegisterType&lt;IUser, Loser&gt;(&quot;loser&quot;);

            return new UnityServiceLocatorAdapter(container);
        }
</pre>
<p>Then tell the service locator which adapter you are using.</p>
<pre class="brush: csharp;">
        private void SetupService()
        {
            // CreateLocator returns IServiceLocator in the above method.
            ServiceLocator.SetLocatorProvider(() =&gt; CreateLocator());
        }
</pre>
<p>Then use the locator to return the adapter, which will allow you to use a common interface to resolve your dependencies.</p>
<pre class="brush: csharp;">
        [It, Should(&quot;resolve the type to the default&quot;)]
        public void ResolveType()
        {
            this.SetupService();
           Â              // gets the current adapter for the Ioc Library.
            var resolver = ServiceLocator.Current;             

            // resolves the type.
            var result = resolver.GetInstance(typeof(IUser));

            // verify the result is the right type for the contract.
            result.IsInstanceOf(typeof(User));

            // this user should not have a membership.
            var user = (User)result;
            user.Membership.ShouldBeNull();
        }
</pre>
<h2>Some Caveats.</h2>
<p>Someone named the base service locator class in a java like manner using Impl.</p>
<p>The assemblies for the Unity Ioc are not strong named assemblies.  I had to create a key, sign the assign the assemblies for Unity.<a href="http://github.com/amptools-net/midori-project/zipball/master"> You can download the midori-project</a> which has the signed assemblies for Unity under the vendor folder.</p>
<h2>Further Usage and Reading</h2>
<p>If you would like to check out the spec and see how it might be used, <a href="http://github.com/amptools-net/midori-project/blob/master/specs/midori.core.specs/Services/ServiceLocatorApi_UnityServiceLocatorAdapter.cs">check out the spec in the midori core</a>. This will give you some context.</p>
<p>You can also read more about it on <a href="http://codebetter.com/blogs/glenn.block/archive/2008/10/02/iservicelocator-a-step-toward-ioc-container-service-locator-detente.aspx">codebetter.com</a> as well as the<a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/08/16/it-s-time-for-ioc-container-detente.aspx"> initial post from Jeremy Miller</a> that spawned someone to write this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/switching-between-ioc-libraries-in-net/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>midori notes stardate 9.14.09</title>
		<link>http://www.amptools.net/blog/midori-notes-stardate-9-14-0</link>
		<comments>http://www.amptools.net/blog/midori-notes-stardate-9-14-0#comments</comments>
		<pubDate>Tue, 15 Sep 2009 01:29:10 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ce]]></category>
		<category><![CDATA[dbconnectionstringbuilder]]></category>
		<category><![CDATA[midori]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postress]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=171</guid>
		<description><![CDATA[Geek Specs
Ignore theÂ TrekkieÂ reference. Â I&#8217;ve started to work on the data abstraction layer for Midori, after narrowing down the supported out-of-the-box relational databases. Â In no particular order, they are SqlServer, SqlServerCe, MySql, Postgress, and Sqlite. Its being written in .Net 4.0 and hopefully it should port to Mono.
The main abstraction class Midori.Data.SqlAdapter makes use of the [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><h2>Geek Specs</h2>
<p>Ignore theÂ TrekkieÂ reference. Â I&#8217;ve started to work on the data abstraction layer for Midori, after narrowing down the supported out-of-the-box relational databases. Â In no particular order, they are SqlServer, SqlServerCe, MySql, Postgress, and Sqlite. Its being written in .Net 4.0 and hopefully it should port to Mono.</p>
<p>The main abstraction class <a href="http://github.com/amptools-net/midori/blob/master/src/midori/Data/SqlAdapter.cs">Midori.Data.SqlAdapter</a> makes use of the System.DataÂ interfaces, like <a href="http://msdn.microsoft.com/en-us/library/system.data.idatareader.aspx">System.Data.IDataReader</a>. Obviously this class will grow as other crud operations are added. Â Each RDMS will have a class that will inherit Midori.Data.SqlAdapter, like <a href="http://github.com/amptools-net/midori/blob/master/src/midori/Data/Sqlite/SqliteAdapter.cs">Midori.Data.Sqlite.SqliteAdapter</a>, which will hold code specific to each database.</p>
<p>There is a <a href="http://github.com/amptools-net/midori/blob/master/src/midori/Data/Connection.cs">Connection</a> class that wraps other connection objects and supplies OnConnect and OnClose events, which should be helpful for closing the connection objects for methods that pass back datareader objects.</p>
<h2>Interesting Notes</h2>
<p><a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbconnectionstringbuilder.aspx">System.Data.Common.DbConnectionStringBuilder</a> is a handy class for building and inspecting values of a connection string in a hash like way. Â Some Ado.Net layers, like System.Data.SqlServerCe, does not implement their own connection string builder. While it is nice to have, its not aÂ necessity, especially when the common dbconnectionstringbuilder will suffice.</p>
<p>Postgres or Npgsql, has some interesting behavior. The following select query has Pascal casing for the names of the columns.</p>
<pre class="brush: sql;">SELECT 'column1' AS Column1, 10 AS Age</pre>
<p>However when the DataReader for Postgres returns the names of the columns, they are all lowercase, all the other databases return the column aliases in the same case as specified in SQL.</p>
<p>So in the tests, I had to rewrite the query to use all lowercase column aliases, like so:</p>
<pre class="brush: sql;">SELECT 'column1' AS column1, 10 AS age</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/midori-notes-stardate-9-14-0/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->