Innovation. Imagination. Delivered. RSS 2.0
# Monday, July 27, 2009

Enabling a Web Slice

Web Slices are new feature in IE 8 that allow your users to bookmark specify content on your site. Implementing this feature is easy and can be accomplished in a few lines of code. The keys are:

  1. Use the 'hslice' class
  2. Specify a slice id
  3. Specify an 'entry-title'
  4. Specify 'entry-content'
  5. Use optional attributes (see IE8 Readiness Toolkit)
The code sample below highlights the required attributes in red and the optional attributes in blue.

The Web Slice User Experience

When a user views your web slice enabled page in IE8, the user is presented with a button that allows him/her to add the slice.

A confirmation dialog appears, displaying the name of your web slice and the location.

Once the user has added the slice, a button is added to the browser toolbar. (User can delete the slice by 'right-clicking' the slice name and then choosing delete.)

When the user clicks the slice button. The slice content is displayed. Two buttons give the user the ability to both refresh the slice and to navigate to your page which contains the slice.

Monday, July 27, 2009 9:30:15 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
IE8 | Web Design
# Thursday, July 23, 2009
C# 4.0 New Features: Optional and Named Parameters
    Optional Parameters
  • removes the ceremony of method overloads to assign default values
  • static void GenerateChart(bool copyToWord = false)
    Named Parameters
  • call a method: GenerateChart(copyToWord: true);
Combining the two new features allow you to write concise code and not
specify values that are not needed in methods with a large number of arguments:
  • Old: MethodA('A', null, null, null, false, null);
  • New: MethodA(ArgA: 'A', ArgE: false);
Thursday, July 23, 2009 9:12:54 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
.Net v4.0 | C#
# Wednesday, July 22, 2009
Managed Extensibility Framework (MEF)

Below are my review notes from the 10-4 video on the upcoming Managed Extensibility Framework in version 4.0

  1. A new library available in v4.0
  2. Software entities should be open to extension, but closed to modification (Open/Closed Principle)
  3. Basics:
    • An application is built of parts or individual pieces composed together
    • Three Steps:
      1. Export a part (Attribute: [Export(typeof(IMortgageCalculator))])
      2. Import a part (Attribute: [Import(typeof(Logger))])
      3. Compose a part
        • Catalogs provide the parts (TypeCatalog, AssemblyCatalog, DirectoryCatalog, AggregatingCatalog)
        • Container is the matchmaker
  4. Why? - Build a network aware app without changing the core window code (i.e. extend behavior without modifying code)

Sample
namespace Sample
{
	public interface IMortgageRateRepository
	{
		public IList GetCurrentRates();
	}
}

Notice that in the concrete implementation of the interface we use the Export Attribute

namespace Sample
{
	[Export(typeof(IMortgageRateRepository))]
	public class ELoanMortgageRateRepository: IMortgageRateRepository
	{
		public IList GetCurrentRates()
		{
			return new List();
		}
	}
}

Alot of stuff happening here, we use the export attribute at the class level and then the Import attribute on our dependency. I also want to point out that we no longer 'new' up an object. Instead we implement the IPartImportsSatisfiedNotification interface and move out binding logic to that event handler (basically we can't use the objects until they have been imported by the container).

namespace Sample
{
	[Export]
	public partial class MortgageRates: Window, IPartImportsSatisfiedNotification
	{
		[Import]
		IMortgageRateRepository MortgageRateRepository  { get; set; }

		public MortgageRates()
		{
			InitializeComponent();

			//MortgageRateRepository = new MortgageRateRepository();
			//grid.ItemSource = MortgageRateRepository.GetCurrentRates();
		}

		public void OnImportsSatisified()
		{
			Dispatcher.Invoke(new Action(() =>
			{
				MortgageRateRepository = new MortgageRateRepository();
				grid.ItemSource = MortgageRateRepository.GetCurrentRates();	
			}));
		}
	}
}

Finally, where the magic happens. We create an AssemblyCatalog and then a CompositionContainer. Notice that instead of 'Newing' up an instance of the window directly. We get an instance of the exported object from the container.

namespace Sample
{
	public partial class App: Application
	{
		var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
		var container = new CompositionContainer(catalog);

		var window = container.GetExportedObject<MortgageRates>();
		//var window = new MortgageRates();

		window.Show();
	}
}
Wednesday, July 22, 2009 8:47:20 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
.Net v4.0 | Extensibility
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Christopher L Price
Sign In
Statistics
Total Posts: 13
This Year: 0
This Month: 0
This Week: 0
Comments: 0
Themes
Pick a theme:
All Content © 2010, Christopher L Price
DasBlog theme 'Business' created by Christoph De Baene (delarou)