<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: IServiceProvider Extension Method</title>
	<atom:link href="http://codecube.net/2009/08/iserviceprovider-extension-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://codecube.net/2009/08/iserviceprovider-extension-method/</link>
	<description>Joel Martinez' weblog</description>
	<lastBuildDate>Wed, 14 Mar 2012 12:26:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Kevin Driedger</title>
		<link>http://codecube.net/2009/08/iserviceprovider-extension-method/comment-page-1/#comment-853</link>
		<dc:creator>Kevin Driedger</dc:creator>
		<pubDate>Tue, 03 Nov 2009 15:18:14 +0000</pubDate>
		<guid isPermaLink="false">http://codecube.net/?p=169#comment-853</guid>
		<description>The code snippet did not compile.  Perhaps the following is better:
    public static class ServiceProviderExtension
    {
        public static T GetService(this IServiceProvider provider) where T : class
        {
            return provider.GetService(typeof(T)) as T;
        }

        public static K GetService(this IServiceProvider provider)
            where T : class, K
            where K : class
        {
            return provider.GetService(typeof(T)) as K;
        }

        public static K GetService(this IServiceProvider provider, Type type)
            where K : class
        {
            return provider.GetService(type) as K;
        }

        public static K GetService(this IServiceProvider provider, string type)
            where K : class
        {
            return provider.GetService(Type.GetType(type)) as K;
        }
    }</description>
		<content:encoded><![CDATA[<p>The code snippet did not compile.  Perhaps the following is better:<br />
    public static class ServiceProviderExtension<br />
    {<br />
        public static T GetService(this IServiceProvider provider) where T : class<br />
        {<br />
            return provider.GetService(typeof(T)) as T;<br />
        }</p>
<p>        public static K GetService(this IServiceProvider provider)<br />
            where T : class, K<br />
            where K : class<br />
        {<br />
            return provider.GetService(typeof(T)) as K;<br />
        }</p>
<p>        public static K GetService(this IServiceProvider provider, Type type)<br />
            where K : class<br />
        {<br />
            return provider.GetService(type) as K;<br />
        }</p>
<p>        public static K GetService(this IServiceProvider provider, string type)<br />
            where K : class<br />
        {<br />
            return provider.GetService(Type.GetType(type)) as K;<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

