Poor mans composite UI or separating out controllers in MVC3

I was looking to create a simple composite UI style application in Microsoft MVC3. What I want is a host MVC application that will compose its UI from other Controllers and Views packaged in other DLLs. The concept comes from autonomous components and SOA where a service owns not only its traditional business services but all the data and almost-all of the UI.

I thought I would be overriding controller builders, adding configuration, etc, etc, but actually this “poor-mans” variant is very easy. Here are the steps I followed;

  1. Create your Host MVC3 web application (Host.proj), for the sake of this example choose the Internet application so you get the default HomeController
  2. Create your satellite MVC3 controller by creating a standard class library project, called Satellite.proj
  3. Add a reference in Satellite to System.Web.Mvc
  4. Create a controller for your satellite, say MyController. Add an ActionResult such as;
  5.  
    public class MyController : Controller 
    { 
      public ActionResult MyInformation() 
      {
        return View("MyInformation2");
      }
    } 
  6. Create the View folders for your controller in the Satellite project, e.g. Views\My\
  7. Now for linking them together. I just added a project reference from Host to Satellite in order to grab the DLL. The Views are slightly harder, I used a post build event in the Satellite such as; xcopy “$(ProjectDir)Views” “$(SolutionDir)Host\Views” /E /R /Y
  8. That’s it. Just add some code to use the controller, such as placing the following in the index view;
  9. @Html.Action("MyInformation","My")
    

    Edit: Note you get errors complaining that ‘there is no build provider registered for the extension’ you need add a dummy web.config to the project, follow these instructions;
    Using Razor in a class library

    Advertisements

Using NuGet with Visual Studio Express

A quick “tip”. Currently Visual Studio C# 2010 Express cannot install the NuGet extension. To workaround the problem you must have Visual Studio Web Developer Express. The NuGet extensions has been signed to work with VWD. Then to install a NuGet package for your VCE project do the following (it’s not nice);
1. Create your project in VCE, save and close
2. Open the project in VWD, it will probably complain but just ignore it
3. Run your NuGet command, e.g. Install-Package
4. Save and close VWD
5. Reopen VCE, add reference and browse to the packages folder that is now in your solution.
There, it’s not nice but it does work

Workaround for problems Launching Performance Analyzer

Over the past couple of weeks I have been trying to use the Visual Studio 2010 Performance Analyizer on a web site but kept on getting;

VSP 7008: ASP.net exception: “The web site could not be configured correctly; getting ASP.NET process information failed. Requesting ‘http://localhost/VSEnterpriseHelper.axd’ returned an error: The remote server returned an error: (404)

The site is a relatively complex IIS6 site with a number of smoke and mirror redirects so I guessed this complexity was confusing the tools. I contacted Microsoft Support to help. During a shared-desktop session with support it started working! Ah the curse of the support person making it work just by looking at it. What actually happened is that when I launched the Performance Wizard I incorrectly gave it a file URL (\\localhost) rather than a web URL. The wizard prompted to say there were no DLLs to profile but I said to continue (not realising my mistake). The profile finished with no results. I corrected the problem (//localhost) by editing the resulting profile NOT by creating via a new wizard. It works?! So I had created a workaround Confused smile. I then manually added the missing target DLLs and re-ran the profile. No problems, everything worked.

There you go, if you are running IIS6 and having problems getting the Profiler to connect, why not try this ridiculous workaround.

How to add a link to a project folder in Visual Studio

I’ve had a quick play with adding the contents of a folder from another project, i.e. I want to add links to all the files in another project’s folder. So for example; I have a project called ConsoleApplication1 and I want to ensure it always has links to the images in another project called ClassLibrary1 (yes nice names eh). So first create a folder with the same name, e.g. images, in ConsoleApplication1. Add a link to one of the files in ClassLibrary1\Images (Add existing item->add as link). Unload ConsoleApplication1 and Edit the project file. Locate the Content Include and replace it as follows;

<ItemGroup>
  <Content Include="..\ClassLibrary1\images\*.*">
    <Link>images\%(RecursiveDir)%(FileName)</Link>
  </Content>
</ItemGroup>

So whatever changes you make to ClassLibrary1\Images will automatically be reflected in ConsoleApplication\Images. It’s early days but it seems to run ok.

Getting a Logitech mouse to work with Visual Studio

Recently my trusty Microsoft Explorer mouse broke, so I decided to invest in a Logitech Performance Mouse MX. The idea was that I could use some of the extra button to help me do stuff in Visual Studio. However, once installed it didn’t seem to work with VS. The left/right buttons and the vertical scroll worked but nothing else. The solution is to go to the All Programs->Startup folder and change the Set Point program to run as Administrator. Sure you’ve opened up another security hole but I want a mouse that works.

Visual Studio no longer opens files from Windows Explorer?

“There was a problem sending the command to the program.”

This has been frustrating me for a couple of days now so I decided to see what the issue was. Apparently it appears that the problem is due to couple of issues;

  1. I’d marked Visual Studio 2008 to ‘run as Administrator’
  2. I have multiple versions of Visual Studio

Apparently when you have multiple copies of VS the shell launches the Visual Studio selector program to work out which version it should launch. However, since the selector is running under the normal UAC state it gets a little confused. So rather than set the selector to Admin I returned Visual Studio back to it normal state and I can now open the files.