<?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>The Redeblog</title>
	<atom:link href="http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blogs.geniuscode.net/JeremiahRedekop</link>
	<description>on the edge of relevance</description>
	<lastBuildDate>Mon, 07 Nov 2011 22:27:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>OrchardProject + WebApi = interesting</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=565</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=565#comments</comments>
		<pubDate>Mon, 07 Nov 2011 20:30:05 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[IOC]]></category>
		<category><![CDATA[orchard]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=565</guid>
		<description><![CDATA[Update: Code for the module is available on GitHub. Orchard is really cool for CMS solutions, however, I am learning more about dependency injection, inversion of control, etc, and what I see in orchard is very interesting. Asp.net mvc does well to de-couple pieces of the application when it comes to handling routes, but something [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: Code for the module is available on <a href="https://github.com/jeremiahredekop/WCF-WebApi-Orchard-Module">GitHub</a>.</p>
<p>Orchard is really cool for CMS solutions, however, I am learning more about dependency injection, inversion of control, etc, and what I see in orchard is very interesting.</p>
<p>Asp.net mvc does well to de-couple pieces of the application when it comes to handling routes, but something is still missing. With asp.net mvc, you have to deploy these pieces along with the application, and perhaps discover them with mef, autofac, etc, but what about updates? If you wanted to update your modules, you have to FTP them to the application root, and re-write the dlls.</p>
<p>Is there an easier way to deploy updates, what about an application that could update itself????????</p>
<h3>Nuget to the rescue</h3>
<p>Phil Hack (@Haacked) wrote something on his blog about building a self-updating site using nuget (<a href="http://haacked.com/archive/2011/01/15/building-a-self-updating-site-using-nuget.aspx">link</a>.) This is really cool because it allows you to package up an application update, and the application can update itself.</p>
<p>However&#8230; the scenario I am going for is really about multiple modules.</p>
<h3>Orchard CMS</h3>
<p>Orchard uses Nuget, and is fully able to handle modules. From inside of the orchard application&#8217;s dashboard, I can install modules, as well as updates to those modules. The modules can also state dependencies, which are installed automatically.</p>
<h3>Getting Started</h3>
<p>To get started, first <a href="http://orchardproject.net/download">download</a> an installation of Orchard CMS.  I used the core recipe, as this is going to be more of a rest endpoint:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/install.png"><img class="alignnone size-full wp-image-566" title="install" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/install.png" alt="" width="619" height="326" /></a></p>
<p>Then you will want to <a href="http://orchardproject.net/docs/Command-line-scaffolding.ashx">enable</a> the code-generation module.  Now you can create a module like using the orchard.exe command that should be in the bin folder of your application.  I created a module called myRestfulModule:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/createModule.png"><img class="alignnone size-full wp-image-567" title="createModule" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/createModule.png" alt="" width="642" height="107" /></a></p>
<p>Orchard just generated a module for us, and placed it in the /Modules directory inside the Orchard web application&#8217;s folder structure.  This means that the module is already installed, just not yet activated.</p>
<p>I looked in visual studio, and my new module was not included automatically in the solution, so I added it.  Here is my module: as you can see, it already has references to orchard dlls.</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/vsModule.png"><img class="alignnone size-full wp-image-570" title="vsModule" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/vsModule.png" alt="" width="292" height="435" /></a></p>
<p>I tweaked the module.txt file to look something like this:</p>
<pre class="brush: plain; title: ; notranslate">
Name: myRestfulModule
AntiForgery: enabled
Author: Jeremiah Redekop
Website: http://blogs.geniuscode.net/JeremiahRedekop
Version: 0.5.0
OrchardVersion: 0.5.0
Description: A sample restful endpoint using wcfwebapi
Features:
    myRestfulModule:
        Description: Hello world using rest from inside orchard.</pre>
<p>Which then gives Orchard the ability to render the module in the admin module library like this:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/moduleListing.png"><img class="alignnone size-full wp-image-569" title="moduleListing" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/moduleListing.png" alt="" width="1002" height="245" /></a></p>
<p>We can just go ahead and enable the module. Now let&#8217;s get the module doing something interesting. Go ahead and use nuget to install <a href="http://nuget.org/List/Packages/WebApi.All">WebApi.All</a>, which is good to start. <em>(By the way, I started out with this <a href="http://orchardproject.net/docs/Building-a-hello-world-module.ashx">tutorial</a> on the orchard site, but had to tweak it to work with webapi.)</em></p>
<h3>The details</h3>
<p>We need to make a few tweaks:</p>
<ul>
<li>Orchard ROOT: Modify Web.config on Orchard application root &#8211; allow asp.net compatibility</li>
<li>MODULE: Create Rest Endpoint &#8211; same as before with one tweak</li>
<li>MODULE: Create Route Provider &#8211; helps orchard with routing requests to our module</li>
</ul>
<p>Orchard Application Web.config:</p>
<pre class="brush: xml; title: ; notranslate">
  &lt;system.serviceModel&gt;
    &lt;serviceHostingEnvironment aspNetCompatibilityEnabled=&quot;true&quot; multipleSiteBindingsEnabled=&quot;true&quot;&gt;&lt;/serviceHostingEnvironment&gt;
  &lt;/system.serviceModel&gt;
</pre>
<p>This is the Rest endpoint. I am using the <a href="http://www.nuget.org/List/Packages/Fabricator">Fabricator</a> library just to mock up a whole bunch of people. I need this class to implement IDependency for Orchard to create it properly</p>
<pre class="brush: csharp; highlight: [3]; title: ; notranslate">
[ServiceContract]
    public class PeopleService
        : IDependency // required for orchard
    {
        private static readonly List _people = Fabrication.Fabricator.Generate(500).ToList();

        [WebGet]
        public IQueryable GetPeople()
        {

            return _people.AsQueryable();
            //return new EnumerableQuery(new Person[]{});
        }

        [WebGet(UriTemplate = &quot;{name}&quot;)]
        public Person GetPerson(string name) {
            return _people.Single(p=&gt; p.Name == name);
        }
    }
</pre>
<p>Here is the route provider that uses the orchard convention of being at the root of your module. Orchard will use this to route requests to the rest endpoint. If you look at the extenson method, the goodies are there.</p>
<pre class="brush: csharp; title: ; notranslate">
    public class Routes : IRouteProvider {
        private static readonly ServiceRoute _route = MapServiceRoute(typeof (PeopleService), &quot;myRestfulModule/People&quot;);
        public IEnumerable GetRoutes() {
            return new[] {
                new RouteDescriptor {
                    Priority = 1,
                    Route = _route
                }
            };
        }

        public void GetRoutes(ICollection routes) {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        private static ServiceRoute MapServiceRoute(Type serviceType, string routePrefix, HttpConfiguration configuration = null, object constraints = null, bool useMethodPrefixForHttpMethod = true)
        {
            if (configuration == null)
                configuration = new WebApiConfiguration(useMethodPrefixForHttpMethod);

            var serviceHostFactory = new HttpServiceHostFactory { Configuration = configuration };
            var webApiRoute = new WebApiRoute(routePrefix, serviceHostFactory, serviceType) { Constraints = new RouteValueDictionary(constraints) };
            return webApiRoute;
        }
    }
</pre>
<p>Now by navigating to the url, you can see the end result.</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/endresult.png"><img class="alignnone size-full wp-image-571" title="endresult" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/11/endresult.png" alt="" width="656" height="605" /></a></p>
<h2>Conclusion</h2>
<p>This is a prototype of using an orchard module to expose rest endpoints.  The main benefit, I believe, is the ability to expose and update endpoints independant of any application code.  Once you deploy your orchard application, you don&#8217;t have to redeploy.  All you have to do is publish updates to your modules, and then install them from the application&#8217;s admin panel.</p>
<p>There are downsides, such as having a dependency on Orchard, but the current release is production-ready.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=565</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The located assembly&#8217;s manifest definition does not match the assembly reference.</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=546</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=546#comments</comments>
		<pubDate>Fri, 28 Oct 2011 09:00:05 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Assemblies]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=546</guid>
		<description><![CDATA[Sometimes I get errors like these: Could not load file or assembly &#8216;gcRelayVisitor&#8217; or one of its dependencies. The located assembly&#8217;s manifest definition does not match the assembly reference. (Exception from HRESULT: 0&#215;80131040) You need to do a few things to turn on Assembly Load Trace: First, modify the registry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion by adding: DWORD [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I get errors like these:</p>
<blockquote><p>Could not load file or assembly &#8216;gcRelayVisitor&#8217; or one of its dependencies. The located assembly&#8217;s manifest definition does not match the assembly reference. (Exception from HRESULT: 0&#215;80131040)</p></blockquote>
<p>You need to do a few things to turn on Assembly Load Trace:</p>
<p>First, modify the registry in <em>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion</em> by adding:</p>
<ul>
<li>DWORD ForceLog set value to 1</li>
<li>DWORD LogFailures set value to 1</li>
<li>DWORD LogResourceBinds set value to 1</li>
</ul>
<p>Then RESTART your pc.</p>
<p>Now we&#8217;re ready to run fuslogvw (<a href="http://msdn.microsoft.com/en-us/library/e74a18c4%28v=VS.100%29.aspx" target="_blank">docs</a>).  I then got this output:</p>
<pre class="brush: plain; highlight: [38]; title: ; notranslate">
*** Assembly Binder Log Entry  (10/27/2011 @ 4:55:05 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = WIN-R2MC10THE6H\Jeremiah Redekop
LOG: DisplayName = gcRelayVisitor
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: gcRelayVisitor | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Jeremiah Redekop/documents/visual studio 2010/Projects/ProductCatalog/ProductCatalog/
LOG: Initial PrivatePath = C:\Users\Jeremiah Redekop\documents\visual studio 2010\Projects\ProductCatalog\ProductCatalog\bin
LOG: Dynamic Base = C:\Users\Jeremiah Redekop\AppData\Local\Temp\Temporary ASP.NET Files\root\a9caded3
LOG: Cache Base = C:\Users\Jeremiah Redekop\AppData\Local\Temp\Temporary ASP.NET Files\root\a9caded3
LOG: AppName = cc40dd82
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Jeremiah Redekop\documents\visual studio 2010\Projects\ProductCatalog\ProductCatalog\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Jeremiah Redekop/AppData/Local/Temp/Temporary ASP.NET Files/root/a9caded3/cc40dd82/gcRelayVisitor.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jeremiah Redekop/AppData/Local/Temp/Temporary ASP.NET Files/root/a9caded3/cc40dd82/gcRelayVisitor/gcRelayVisitor.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jeremiah Redekop/documents/visual studio 2010/Projects/ProductCatalog/ProductCatalog/bin/gcRelayVisitor.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\Jeremiah Redekop\documents\visual studio 2010\Projects\ProductCatalog\ProductCatalog\bin\gcRelayVisitor.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: gcRelayVisitor35, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Comparing the assembly name resulted in the mismatch: NAME
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
</pre>
<p>So for me it seems like the assembly name is gcRelayVisitor35, while my application is expecting gcRelayVisitor. Uhoh.  Here is the project file for my library:</p>
<pre class="brush: xml; highlight: [12]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;Project ToolsVersion=&quot;4.0&quot; DefaultTargets=&quot;Build&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
    &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
    &lt;ProductVersion&gt;8.0.30703&lt;/ProductVersion&gt;
    &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
    &lt;ProjectGuid&gt;{D335EFF0-D0F5-4B25-A65A-A7FD3268C0F5}&lt;/ProjectGuid&gt;
    &lt;OutputType&gt;Library&lt;/OutputType&gt;
    &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
    &lt;RootNamespace&gt;GeniusCode.Components.RelayVisitor&lt;/RootNamespace&gt;
    &lt;AssemblyName&gt;gcRelayVisitor35&lt;/AssemblyName&gt;
    &lt;TargetFrameworkVersion&gt;v4.0&lt;/TargetFrameworkVersion&gt;
    &lt;FileAlignment&gt;512&lt;/FileAlignment&gt;
  &lt;/PropertyGroup&gt;
</pre>
<p>So it looks like my assembly name is indeed gcRelayVisitor35.  However, since this is a nuspec package I am using for my reference, a careful look at the nuspec package shows that I am renaming the dll:</p>
<pre class="brush: xml; highlight: [16]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;package xmlns=&quot;http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd&quot;&gt;
  &lt;metadata&gt;
    &lt;id&gt;gcRelayVisitor&lt;/id&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;title&gt;Relay Visitor&lt;/title&gt;
    &lt;authors&gt;JeremiahRedekop,Ryan D Hatch&lt;/authors&gt;
    &lt;owners&gt;GeniusCode,LLC&lt;/owners&gt;
    &lt;projectUrl&gt;https://github.com/GeniusCode/GeniusCode.Components.RelayVisitor&lt;/projectUrl&gt;
    &lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
    &lt;description&gt;Vistor class that allows for delegates to be assigned for simple recursive operations&lt;/description&gt;
    &lt;summary&gt;Delegate based Visitor class&lt;/summary&gt;
    &lt;tags&gt;visitor, delegate&lt;/tags&gt;
  &lt;/metadata&gt;
  &lt;files&gt;
    &lt;file src=&quot;gcRelayVisitor35\bin\Release\gcRelayVisitor35.dll&quot; target=&quot;lib\net40\gcRelayVisitor.dll&quot; /&gt;
&lt;file src=&quot;gcRelayVisitorSl4\bin\Release\gcRelayVisitorSl4.dll&quot; target=&quot;lib\sl40\gcRelayVisitor.dll&quot; /&gt;
  &lt;/files&gt;
&lt;/package&gt;
</pre>
<p>So it seems that the filename needs to match the assembly name.  Once I fix this, I should be set to go <img src='http://blogs.geniuscode.net/JeremiahRedekop/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=546</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Access: What is Dependency Inversion good for?</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=532</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=532#comments</comments>
		<pubDate>Sun, 28 Aug 2011 07:33:51 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IOC]]></category>
		<category><![CDATA[LLBLGen]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=532</guid>
		<description><![CDATA[After some good Pluralsight learning, I&#8217;ve been pondering the value of Dependency Inversion.  I&#8217;ve always understood the practice of organizing code and maintaining a convention, but now have a cleaner picture. Higher level items should not have a dependency on lower level items. I am going to use asp.net mvc in an upcoming application, so [...]]]></description>
			<content:encoded><![CDATA[<p>After some good Pluralsight learning, I&#8217;ve been pondering the value of Dependency Inversion.  I&#8217;ve always understood the practice of organizing code and maintaining a convention, but now have a cleaner picture.</p>
<p>Higher level items should not have a dependency on lower level items.</p>
<p>I am going to use asp.net mvc in an upcoming application, so will use it as an example.</p>
<p>My controller needs to access some kind of data store, where is my DAL magic going to reside?  We use LLBLGen for SQL access, but I am not going to have a reference to LLBLGen dlls in my mvc application.  I am not going to be making calls to the database from my controller.  I am not even going to reference directly the dll that will be making those calls.</p>
<p>This is not crazy, or wasting time.  Instead of just using the IRepository interface, I will be making interfaces for each &#8220;datamanager&#8221; type that I will need.  Those interfaces will expose methods beyond a simple IQueryable&lt;T&gt; property that can be mocked in debug mode, or implemented at runtime.</p>
<p>The main benefit is that once the dependency has been inverted in this way,  the MVC Controller has been cleanly isolated from the llblgen (or EF, NHibernate, etc) datamanager.</p>
<p>The goal here is NOT that we would allow multiple implementations of the datamanger interface to switch ORMs (although we could). Instead, the goal is to allow mocking at runtime, and updating of the datamanager libraries without having to recompile the whole application.</p>
<p>I&#8217;m hoping to tidy &amp; publish some of the libraries we&#8217;re using internally.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=532</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstracting IOC Containers &#8211; Part 3 : ViewModelLocator Intro</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=526</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=526#comments</comments>
		<pubDate>Wed, 27 Jul 2011 01:12:26 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IOC]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=526</guid>
		<description><![CDATA[When acquiring an instance of the viewmodel, the locator should consider different sources and options. Here is our default list of InstanceProviders we&#8217;ll use. The arguement passed into the method could be a MEF provider, or any other IOC. Because most IOCs don&#8217;t work at design time, we only add them in if we&#8217;re in [...]]]></description>
			<content:encoded><![CDATA[<p>When acquiring an instance of the viewmodel, the locator should consider different sources and options.</p>
<p>Here is our default list of InstanceProviders we&#8217;ll use. The arguement passed into the method could be a MEF provider, or any other IOC.  Because most IOCs don&#8217;t work at design time, we only add them in if we&#8217;re in runtime mode.</p>
<pre class="brush: csharp; title: ; notranslate">
        protected  List&lt;IInstanceProvider&lt;T&gt;&gt; GetDefaultSources(IInstanceProvider&lt;T&gt; locateProviderToUse)
        {
            var list = new List&lt;IInstanceProvider&lt;T&gt;&gt;();

            var myType = GetType();
            var designMode = IsInDesignMode;

            if (myType.GetSharedValueAttributeUsage())
                list.AddTypeKeyedSingletonCachingInstanceProvider();

            list.AddFactoryInstanceProvider();

            if (designMode)
                list.AddMockingInstanceProvider();
            else
            {
                if(locateProviderToUse != null)
                    list.Add(locateProviderToUse);

                if (myType.GetRuntimeMockBehavior() == RuntimeMockingBehavior.AllowAtRuntime)
                    list.AddMockingInstanceProvider();

            }

            return list;
        }
</pre>
<p>Our class will be able to use this to acquire an instance of the viewmodel, but we&#8217;ll take a look at that later.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=526</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstracting IOC Containers &#8211; Part 2: Simple MEF</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=522</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=522#comments</comments>
		<pubDate>Wed, 27 Jul 2011 01:01:15 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IOC]]></category>
		<category><![CDATA[MEF]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=522</guid>
		<description><![CDATA[Based upon the last post, it is now possible to abstract MULTIPLE layers of IOC. All you need is to declare a priority list. In this post, we&#8217;re going to support locating with a MEF based provider. This is just a simple example, wheras in MVVM-land, you will want something a little heavier to databind [...]]]></description>
			<content:encoded><![CDATA[<p>Based upon the last post, it is now possible to abstract MULTIPLE layers of IOC.  All you need is to declare a priority list.</p>
<p>In this post, we&#8217;re going to support locating with a MEF based provider.  This is just a simple example, wheras in MVVM-land, you will want something a little heavier to databind to.</p>
<p>So for now, here is how our MEF implementation of an InstanceSource looks.  We inherit from InstanceProviderBase<T,TArgs> which does alot of the implementation of IInstanceProvider<T> for us.</p>
<pre class="brush: csharp; title: ; notranslate">
    public class MefInstanceProvider&lt;T, TMefContract, TMetadata, TArgs&gt; : InstanceProviderBase&lt;T, TArgs&gt;
        where T : class, TMefContract
        where TMetadata : class
        where TArgs: class
    {

        private readonly CompositionContainer _Container;
        public MefInstanceProvider(CompositionContainer container)
        {
            _Container = container;
        }

        public Func&lt;TArgs,IEnumerable&lt;Lazy&lt;TMefContract,TMetadata&gt;&gt;, Lazy&lt;TMefContract,TMetadata&gt;&gt; Selector { get; set; }
        public Func&lt;TArgs,Lazy&lt;TMefContract,TMetadata&gt;,bool&gt; Predicate {get;set;}

        protected override bool Try_Perform_Acquire_With_Args&lt;R&gt;(out bool wasCached, TArgs args, out R result)
        {
            result = null;
            wasCached = false;

            var lazies = _Container.GetExports&lt;TMefContract, TMetadata&gt;();

            if (Predicate != null)
                lazies = lazies.Where(a =&gt; Predicate(args, a));

            Lazy&lt;TMefContract, TMetadata&gt; myLazy =
                lazies.Count() &gt; 1 ? Selector(args, lazies) : lazies.SingleOrDefault();

            if (myLazy != null)
            {
                result = (R)myLazy.Value;
                return true;
            }

            return false;
        }
    }
</pre>
<p>Something really cool is that we have both a predicate and a selector as public properties.  This means that we can inject the delegates from the outside.  Here is an extension method that supports looking for a class we use for our data access:</p>
<pre class="brush: csharp; title: ; notranslate">
        public static void AddMefLLBLGenManagerSource&lt;TSessionInfo,TLinqMetadata&gt;(
            this IList&lt;IInstanceProvider&lt;IEntityManager&lt;TSessionInfo, TLinqMetadata&gt;&gt;&gt; input, CompositionContainer container)
        where TSessionInfo : class
            where TLinqMetadata : class, ILinqMetaData, new()
        {
            var mp = new MefInstanceProvider&lt;IEntityManager&lt;TSessionInfo, TLinqMetadata&gt;, IEntityManager, IDataManagerMetaData, EntityManagerLocateArgs&gt;(container)
            {
                Predicate = (args, mefExport) =&gt; mefExport.Metadata.EntityTypeName == args.EntityType.Name
            };

            input.Add(mp);
        }
</pre>
<p>Because this is an extension method, we can easy take a list of providers, and add support to find a mef export of IEntityManager using IDataManagerMetaData.  The key is the predicate assignment, because it is here that we say that when the arguement object comes in, we are going to use it to find the correct export for the EntityType.</p>
<p>Now let&#8217;s use it.  I have a LLBLGen data manager that knows how to do stuff for the CustomerEntity.  </p>
<p>Here is the declaration.  We are using a custom attribute to export this using mef:</p>
<pre class="brush: csharp; title: ; notranslate">
    [ExportDataManager(typeof(CustomerEntity))]
    public class CustomerManager : SessionPlaceHolder.EntityManager&lt;CustomerEntity&gt;
    {
</pre>
<p>And then we can create a list of InstanceProviders, and add our mef manager source, by calling AddMefLLBLGenManagerSource() passing in a mef container.</p>
<pre class="brush: csharp; title: ; notranslate">[/csharp]
    [TestClass]
    public class SimpleLocate
    {
        private static CompositionContainer container;

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            container = new CompositionContainer(new TypeCatalog(typeof(CustomerManager)));
        }

        [TestMethod]
        public void SimpleResolve()
        {
            var list = new List&lt;IInstanceProvider&lt;IEntityManager&lt;Session,LinqMetaData&gt;&gt;&gt;();
            list.AddMefLLBLGenManagerSource(container);

            var result = list.TryAcquireFromEnumerable(new EntityManagerLocateArgs() { EntityType = typeof(CustomerEntity) });
            Assert.IsTrue(result.ResultSuccessful);

            Assert.IsTrue(result.Result is CustomerManager);
        }
1</pre>
<p>The end result is that we have a list of instance providers that is able to acquire an instance of an EntityManager, using MEF.  So why all this extra work of having a list of InstanceProviders?  Each case is different, and this approach allows you to not only abstract away your IOC container, but multiple IOC containers or behaviors (factory, mock, cache), as the previous post indicates.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=522</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstracting IOC Containers (or anything!)</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=516</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=516#comments</comments>
		<pubDate>Mon, 25 Jul 2011 19:59:22 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IOC]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=516</guid>
		<description><![CDATA[We&#8217;re working on a concept to abstract away not just IOC containers, but any source. Basically, you have a list of Instance providers, which look like this: We already implemented the following providers: Factory (default constructor) Cache Mock Locate The locating part is quite abstract &#8211; you could use any IOC you want. We coded [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>We&#8217;re working on a concept to abstract away not just IOC containers, but any source.</li>
</ul>
<p>Basically, you have a list of Instance providers, which look like this:</p>
<pre class="brush: csharp; title: ; notranslate">
    public interface IInstanceProvider&lt;T&gt;
        where T : class
    {
        IAcquireResult&lt;T, R&gt; PerformAcquire&lt;R&gt;(object args = null) where R : class, T;
    }

    public interface IInstanceProvider&lt;T, TArgs&gt; : IInstanceProvider&lt;T&gt;
        where T : class
        where TArgs : class
    {
        IAcquireResult&lt;T, R&gt; PerformAcquire&lt;R&gt;(TArgs args) where R : class, T;
    }
</pre>
<p>We already implemented the following providers:</p>
<ul>
<li>Factory (default constructor)</li>
<li>Cache</li>
<li>Mock</li>
<li>Locate</li>
</ul>
<p>The locating part is quite abstract &#8211; you could use any IOC you want.  We coded up a mef test but it was not as clean to read, wheras this test does a good job:</p>
<pre class="brush: csharp; title: ; notranslate">
        [TestMethod]
        public void Should_Perform_AutoCache()
        {
            var list = new List&lt;IInstanceProvider&lt;IPerson&gt;&gt;();
            list.AddInstanceCachingInstanceProvider();
            list.AddFactoryInstanceProvider();
            list.AddMockingInstanceProvider();

            // factory
            Person p;
            var result1 = list.TryAcquireFromEnumerableDerived(out p);

            // cache
            Person p2;
            var result2 = list.TryAcquireFromEnumerableDerived(out p2);
            Assert.AreSame(p,p2);

            // mock (NOT LOCATE!!)
            IPerson p3;
            list.TryAcquireFromEnumerableDerived(out p3);
            Assert.AreEqual(&quot;Ryan&quot;, p3.Name);

            // cache
            IPerson p4;
            list.TryAcquireFromEnumerableDerived(out p4);
            Assert.AreSame(p3,p4);
        }
</pre>
<p>As you can see, our cache is able to store results so that instances are shared, not recreated.  Of course this all depends on the order of the providers in the list, so you only have to add what you want.</p>
<p>The support classes for our tests look like this:</p>
<pre class="brush: csharp; title: ; notranslate">
         public interface IPerson
        {
             [DefaultValue(&quot;Ryan&quot;)]
            string Name { get; set; }
            int Age { get; set; }
        }

        public class Person : IPerson
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=516</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My favorite Visual Studio Color Scheme</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=512</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=512#comments</comments>
		<pubDate>Sat, 23 Jul 2011 08:13:01 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=512</guid>
		<description><![CDATA[I thought I would share my favorite VS setup for fonts and colors. Here is how it looks: In addition to downloading my settings file, you&#8217;ll also need to download the font &#8220;Envy Code R&#8221;, which is available here: http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released]]></description>
			<content:encoded><![CDATA[<p>I thought I would share my favorite VS setup for fonts and colors.</p>
<p>Here is how it looks:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/07/2011-07-23_0106.png"><img class="alignnone size-full wp-image-513" title="2011-07-23_0106" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/07/2011-07-23_0106.png" alt="" width="952" height="687" /></a></p>
<p>In addition to downloading <a href="http://data.files.s3.amazonaws.com/assets/Blog/Exported-2011-07-14.vssettings">my settings file</a>, you&#8217;ll also need to download the font &#8220;Envy Code R&#8221;, which is available here: http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=512</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MEF Export + BinaryFormatter.Deserialize() = FAIL</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=496</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=496#comments</comments>
		<pubDate>Mon, 06 Jun 2011 22:31:15 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=496</guid>
		<description><![CDATA[Update: It seems that NetDataContractSerializer also suffers the same flaw, while DataContractSerializer works great.  I suppose this is why DataContractSerializer is used for client/server in wcf.  It seems that these limitations on the other serializers are being exposedby MEF&#8217;s push to compose apps on the fly, instead of traditional static fashion. My friend Ryan is [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update</strong>: It seems that <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.netdatacontractserializer.aspx">NetDataContractSerializer</a> also suffers the same flaw, while DataContractSerializer works great.  I suppose this is why DataContractSerializer is used for client/server in wcf.  It seems that these limitations on the other serializers are being exposedby MEF&#8217;s push to compose apps on the fly, instead of traditional static fashion.</em></p>
<p>My friend Ryan is working on a report application that is going to use datasources packaged up by MEF.</p>
<p>Unfortunately, MEF &amp; BinaryFormatter do not play well together.  Somehow, BinaryFormatter does not &#8220;know&#8221; about assemblies that have been discovered by MEF.</p>
<p>Here is my simple MEF Contract:</p>
<pre class="brush: csharp; title: ; notranslate">
    public interface ISampleMefObject
    {
        object GetObject();
    }
</pre>
<p>And here is my export:</p>
<pre class="brush: csharp; title: ; notranslate">
    [Export(typeof(ISampleMefObject))]
    public class Class1 : ISampleMefObject
    {
        public object GetObject()
        {

            var q = new BinaryFormatter().Deserialize(
                new FileStream(@&quot;C:\Users\JeremiahRedekop\Documents\Visual Studio 2010\Projects\MefTests\MefTests.Serializer\Fun.bak&quot;,
                    FileMode.Open));

            return q;
        }
    }
</pre>
<p>The &#8220;fun.bak&#8221; file is created using this simple console app:</p>
<pre class="brush: csharp; title: ; notranslate">
    class Program
    {
        static void Main(string[] args)
        {
            var entity = new CustomerEntity()
            {
                CustomerId = &quot;CHOPS&quot;
            };

            var c = new BinaryFormatter();
            c.Serialize(new FileStream(args[0], System.IO.FileMode.Create), entity);
        }
    }
</pre>
<p>So anyway, when the code in GetObject() method fires, guess what &#8211; the BinaryFormatter has no clue about the dlls that MEF has discovered, and we get this:</p>
<blockquote><p>System.Runtime.Serialization.SerializationException was unhandled<br />
Message=Unable to find assembly &#8216;Northwind.DAL, Version=1.0.4095.18490, Culture=neutral, PublicKeyToken=null&#8217;.<br />
Source=mscorlib<br />
StackTrace:<br />
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()<br />
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)<br />
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)<br />
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)<br />
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)<br />
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()<br />
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br />
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br />
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)<br />
at MefTests.Module.Class1.GetObject() in C:\Users\JeremiahRedekop\Documents\Visual Studio 2010\Projects\MefTests\MefTests.Module\Class1.cs:line 15<br />
at MefTests.Client.Form1.SetExportToPropertyGrid() in C:\Users\JeremiahRedekop\Documents\Visual Studio 2010\Projects\MefTests\MefTests.Client\Form1.cs:line 41<br />
:</p></blockquote>
<p>Just to show what the project structure is:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/06/2011-06-06_1512.png"><img class="alignnone size-full wp-image-499" title="2011-06-06_1512" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/06/2011-06-06_1512.png" alt="" width="388" height="486" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=496</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Windows Azure at AzureFest</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=487</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=487#comments</comments>
		<pubDate>Wed, 06 Apr 2011 04:15:35 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[VanSlug]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=487</guid>
		<description><![CDATA[Today we had an event sponsored by Vanslug called AzureFest. There are a highlights: can&#8217;t change instance size brand new fancy silverlight ui &#160; Here is what it looks like to create a new hosted service: Things happening: &#160; And here is the output: Just don&#8217;t forget to stop &#38; delete the service, and drop [...]]]></description>
			<content:encoded><![CDATA[<p>Today we had an event sponsored by Vanslug called AzureFest.</p>
<p>There are a highlights:</p>
<ul>
<li>can&#8217;t change instance size</li>
<li>brand new fancy silverlight ui</li>
</ul>
<p>&nbsp;</p>
<p>Here is what it looks like to create a new hosted service:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/Screen-shot-2011-04-05-at-8.14.48-PM.png"><img class="alignnone size-full wp-image-488" title="Screen shot 2011-04-05 at 8.14.48 PM" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/Screen-shot-2011-04-05-at-8.14.48-PM.png" alt="" width="536" height="641" /></a></p>
<p>Things happening:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/Screen-shot-2011-04-05-at-8.50.15-PM.png"><img class="alignnone size-full wp-image-489" title="Screen shot 2011-04-05 at 8.50.15 PM" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/Screen-shot-2011-04-05-at-8.50.15-PM.png" alt="" width="739" height="151" /></a></p>
<p>&nbsp;</p>
<p>And here is the output:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-05_2108.png"><img class="alignnone size-full wp-image-490" title="2011-04-05_2108" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-05_2108.png" alt="" width="959" height="789" /></a></p>
<p>Just don&#8217;t forget to stop &amp; delete the service, and drop the database &amp; db server.  Whew &#8211; no charges!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=487</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authorization in Lightswitch: a summary</title>
		<link>http://blogs.geniuscode.net/JeremiahRedekop/?p=477</link>
		<comments>http://blogs.geniuscode.net/JeremiahRedekop/?p=477#comments</comments>
		<pubDate>Sun, 03 Apr 2011 19:47:41 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[lightswitch]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[VanSlug]]></category>

		<guid isPermaLink="false">http://blogs.geniuscode.net/JeremiahRedekop/?p=477</guid>
		<description><![CDATA[Lightswitch is a very exciting framework for line-of-business applications.  Most business problems are relatively simple, and can be solved with Lightswitch. In the case for complex business problems, you are better off starting from scratch, but Lightswitch will give your clients a more affordable solution, as you finish the project much faster. Beth Massi is [...]]]></description>
			<content:encoded><![CDATA[<p>Lightswitch is a <strong>very</strong> exciting framework for line-of-business applications.  Most business problems are relatively simple, and can be solved with Lightswitch.</p>
<p>In the case for complex business problems, you are better off starting from scratch, but Lightswitch will give your clients a more affordable solution, as you finish the project much faster.</p>
<p>Beth Massi is a Project Manager for Visual at Microsoft, and she has a great video introducing authentication &amp; authorization  in Lightswitch.  I grabbed a few screenshots which I think provide some good highlights.</p>
<h3>Step 1: Create Permissions</h3>
<p>In order to assign permissions to roles and users, you first need to create the permissions on Access Control tab on the property page for the application.</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-list.png"><img class="alignnone size-medium wp-image-478" title="permissions list" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-list-300x168.png" alt="" width="300" height="168" /></a></p>
<h3>Step 2: Check for permissions in code</h3>
<p>Lightswitch does not assign permissions in the ui, you actually have to write code.  There are 2 levels for authorization: Screens &amp; Entities.  Screen authorization will occur at the client level, while entity authorization will occur on the server.  In other words, you will definately want to perform authorization on your entities, but to help your clients, you will also want to perform authorization checks on the client to.  If you only check on the server, you will get an error message like this:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-03_1206.png"><img class="alignnone size-full wp-image-479" title="2011-04-03_1206" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-03_1206.png" alt="" width="573" height="185" /></a></p>
<p><strong>Authorization Screens (Client)</strong></p>
<p>You&#8217;ll need to access the code to accomplish this, but Lightswitch makes it easy by giving you hyperlink to click on to create and assign the correct method:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-I.png"><img class="alignnone size-medium wp-image-480" title="permissions I" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-I-300x110.png" alt="" width="300" height="110" /></a></p>
<p>Then, you can write a method that will calculate whether or not the screen can run:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-II.png"><img class="alignnone size-medium wp-image-481" title="permissions II" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/permissions-II-300x151.png" alt="" width="300" height="151" /></a></p>
<p><strong>Authorization Entity (Server)</strong></p>
<p>Authorizing entities is much like screens, except that we can authorize for delete, insert, read, update, and execute.  These options are available again from the ui of Visual Studio.<strong><br />
</strong></p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/entity-permissions.png"><img class="alignnone size-medium wp-image-482" title="entity permissions" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/entity-permissions-300x182.png" alt="" width="300" height="182" /></a></p>
<p>The code is almost identical, except that the path to the user object is slightly different:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/EntityAuth.png"><img class="alignnone size-medium wp-image-483" title="EntityAuth" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/EntityAuth-300x188.png" alt="" width="300" height="188" /></a></p>
<h3>3: Wire up Roles &amp; Permissions at runtime</h3>
<p>The interesting part of roles &amp; permissions is that you link them in the database at runtime after you deploy.  In the video, Beth goes into detail on this, but here is a shot of the link:</p>
<p><a href="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-03_1211.png"><img class="alignnone size-medium wp-image-484" title="2011-04-03_1211" src="http://blogs.geniuscode.net/JeremiahRedekop/wp-content/uploads/2011/04/2011-04-03_1211-300x111.png" alt="" width="300" height="111" /></a></p>
<p>I think the reason for not hard-coding your roles &amp; permissions together is for cases when one applicaiton might be shared among seperate clients.  This approach gives alot of flexibility.  And if you want to re-use your role &amp; permissions setups, they can easily be created in a stored procedure or something.</p>
<p>Thanks a lot for stopping by, hopefully this summary has been helpful!  Thanks to Beth &amp; the Lightswitch team for such an exciting product!</p>
<p><strong>Links:</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/lightswitch/Video/gg278959" target="_blank">Beth Massi: How Do I Set up Security to Control User Access to Parts of a Visual Studio LightSwitch Application?</a></li>
<li><a href="http://www.microsoft.com/visualstudio/en-us/lightswitch" target="_blank">Microsoft Visual Studio Lightswitch</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.geniuscode.net/JeremiahRedekop/?feed=rss2&#038;p=477</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

