Thursday, September 30, 2010

Programming Entity Framework 2nd Edition

I recently read Julie Lerman’s Programming Entity Framework, 2nd Edition. I have been strongly recommending the first edition to every customer I have worked with in recent years that were planning to use Entity Framework. Julie really did an outstanding job at writing THE definitive learning resource and reference for EF, and the second edition continues that fine tradition.

A fair amount of the book is unchanged from the first edition, other that pointing out small differences here and there for places they enhanced the API (i.e. adding entities on the entity collection instead of on the root object context). But of course there are also some big new features in EF 4 like the ability to work with POCOs and generate the database from the object model instead of the other way around, and Julie does a great job covering these and getting you up to speed on how to use them.

Programming Entity Framework 2nd Edition is definitely the best self-study way to learn EF inside out, and even as someone who knows EF very well myself, I always keep her book handy for reference for when I am trying something a little advanced or different, and can always find the answers in this book.

If you are using Entity Framework in your application, you NEED a copy of this book close by.





Thursday, September 30, 2010 9:59:23 PM (GMT Standard Time, UTC+00:00)
Comments [29]  | 


  Friday, September 17, 2010

New Manifest Manager Utility Available on CodePlex

A long time ago I wrote the Manifest Manager Utility to make it easier to edit ClickOnce manifests for composite application scenarios where the application DLLs are not all directly referenced by the shell application. That code was updated for the release of SCSF 2010, but unfortunately a late breaking change in the framework caused that version to stop working with .NET 4.0 RTM.

The Prism team has taken ownership of that utility from SCSF, and we updated it to work with .NET 4.0. The new version is now available on CodePlex here. Thanks much to Robin Shahan (@robindotnet) for pointing out the fix.

The utility makes it easy to open both the deployment manifest and application manifest of a ClickOnce app at the same time in a single editor to do things like update the publish version, add and remove files, change the application name or the deployment location (provider). Saving saves and signs both manifests in one action, saving the hassle of trying to do everything in the right order across two manifests. You can see the UI here.

9-17-2010 7-38-57 PM





Friday, September 17, 2010 5:40:37 PM (GMT Standard Time, UTC+00:00)
Comments [16]  | 


  Thursday, September 16, 2010

Prism Talk at Sweden .NET Users Group – MEF Modularity Differences

Last night I gave a talk on Prism at the Sweden .NET User Group. It was a great crowd with lots of great questions. Thanks to Tibi and Ulf for inviting me to speak.

I had one little glitch on an on-the-fly demo that I thought I would just put out there as a tip and trick since it tripped me up and I am supposed to be an expert on Prism.

In Prism 4 the option was added to use MEF for the dependency injection container that you can use instead of Unity, since MEF is now part of the framework. That means you have to use MEF attributes to indicate your Exports (similar to registering types with the container in Unity) and Imports (similar to Resolving types with Unity). In my demo, I quickly put together a shell application and a single module with a single view and was placing the view into a region in the shell.

The code for the bootstrapper looks like this:

   1: class Bootstrapper : MefBootstrapper
   2: {
   3:     protected override System.Windows.DependencyObject CreateShell()
   4:     {
   5:         MainWindow win = new MainWindow();
   6:         win.Show();
   7:         return win;
   8:     }
   9:  
  10:     protected override IModuleCatalog CreateModuleCatalog()
  11:     {
  12:         return new ModuleCatalog().AddModule(typeof(Module1.Module));
  13:     }
  14:  
  15:     protected override void ConfigureAggregateCatalog()
  16:     {
  17:         base.ConfigureAggregateCatalog();
  18:         AggregateCatalog.Catalogs.Add(
  19:             new AssemblyCatalog(typeof(Module1.Module).Assembly));
  20:     }
  21: }

 

One thing thing that is different about using MEF in Prism 4 from the way this was done with Unity is the need to add your module assemblies to the AggregateCatalog that is used in the bootstrapper, seen in the ConfigureAggregateCatalog method at the bottom. This makes it so MEF will probe those assemblies and discover the Exports within them. The bootstrapper will automatically discover types in the shell, but you need to tell it what other assemblies you want to have added to the catalog.

Then the module class looks like this:

   1: [ModuleExport(typeof(Module))]
   2: public class Module : IModule
   3: {
   4:     IRegionManager _RegionManager;
   5:     [ImportingConstructor]
   6:     public Module(IRegionManager regionManager)
   7:     {
   8:         _RegionManager = regionManager;
   9:     }
  10:     public void Initialize()
  11:     {
  12:         _RegionManager.RegisterViewWithRegion("MainContent",typeof(UserControl1));
  13:     }
  14: }

Notice that the module needs to Export itself using a custom Export attribute that is part of Prism (think of it as combining the declaration of Export in MEF with the declaration that this is a Module to Prism. I use an [ImportingConstructor] attribute from MEF to indicate the dependencies I need injected, which in this case is just the region manager. The “MainContent” region is declared in the shell with a normal RegionName attached property.

The thing that tripped me up in my demo is that I forgot to put an Export on the UserControl1 that I was using as a view with the RegisterViewWithRegion view discovery mechanism of Prism. I needed to do this:

   1: [Export]
   2: public partial class UserControl1 : UserControl
   3: {...}

 

The reason is that RegisterViewWithRegion uses the container to construct the specified view type. With MEF, the container can’t construct a type unless that type has been marked as an Export in the catalog managed by the container. If I had passed a reference to the view into RegisterViewWithRegion, it would not have been a problem because I could have just new’d up the view myself. But if you use the overload of RegisterViewWithRegion that takes a view type name, Prism uses the container to construct the type, which requires proper registration with the container. For Unity, this would have been no problem because Unity can construct any concrete type without registration by reflecting on its constructors. But MEF always requires the type to be exported in the catalog. Unity 1, MEF 0 in my mind, but maybe I just need to get more used to the Meffy way of doing things. :)


Here are the Slides and Demos from the talk.



Thursday, September 16, 2010 8:18:12 AM (GMT Standard Time, UTC+00:00)
Comments [26]  | 


  Wednesday, September 15, 2010

WCF RIA Services Part 7 – Authentication and Authorization is published

Part 7 of my RIA Services article series has been published here.

This one goes into details on the security features of RIA Services. It shows how things work for configuring and using the membership and role providers in a RIA Services app with the ability to authenitcate the user, authorize calls based on roles, modify the UI based on role, and filter data based on user identity and roles.

The quick and dirty is this:

  • Configure your host site for membership and role providers and forms authentication
  • Add a [RequiresAuthentication] attribute to your domain services
  • Add an AuthenticationDomainService (project item template) to your host site
  • Initialize the WebContext on the client by adding it to the ApplicationLifetimeObjects collection and set its Authentication property to an instance of FormsAuthentication
  • Call Login on the WebContext with user credentials
  • Authorize on the server side with [RequiresRole] attributes
  • Authorize on the client side with WebContext.User.IsInRole

See the article for the full details of the above. :)





Wednesday, September 15, 2010 8:22:14 AM (GMT Standard Time, UTC+00:00)
Comments [34]  | 


  Thursday, September 09, 2010

Sweden Tour

Next week I will be teaching my Architecting WPF and Silverlight Applications class in Stockholm Sweden. You can find more information on that here… if you speak Swedish. :) The class will be conducted in English. Or if you are just curious about the syllabus, I teach this all over the world in both public and onsite classes, so you can find the full syllabus in English here.

While I am in Sweden, I am also going to be giving talks at two user groups in Stockholm:

Build Composite Silverlight and WPF Applications with Prism – Wed 15 Sep – Sweden .NET User Group

Prism is a set of guidance from Microsoft patterns & practices for building loosely coupled, maintainable, and testable composite applications in Silverlight and WPF. In this talk, you will learn about the full range of features of Prism. The first part of the talk will cover what is in the currently released Prism 2.2 version, including modular loading of functionality, UI composition with regions, and loosely coupled communications with commands and pub/sub events. In the second part, you will learn about what is coming in Prism 4, including MVVM guidance, inclusion of the Managed Extensibility Framework for dependency injection, and navigation guidance for switching and managing views. Prism allows you to pick and choose which of these features you want to leverage, and this talk will be a perfect springboard for understanding what is there, what it does for you, and the basics of how to use it.

WCF RIA Services From the Inside Out – Thu 16 Sep - .NET Akademien User Group

WCF RIA Services is a great new capability for quickly building Line of Business Silverlight applications. One problem with technologies like WCF RIA Services is that there is a fair amount of "magic" that happens to make things easy and quick. But that magic can become a liability if you don't know what is going on behind the curtain. Additionally, if you want to do something slightly different than what happens automagically out of the box, then you can be left wondering where to start and what you can get away with. This talk will peel back the skin of WCF RIA Services and give you a good understanding of what is going on in the internals and what customization options you have. You'll get a quick exposure to the external "magic" approach to using RIA Services, and then you will see what kinds of services they are actually creating under the covers, how you can configure and customize those services, and how you can consume those services from clients that don't have the automatic code generation that Silverlight does.

So if you are in Sweden, I hope to see you at one of these events





Thursday, September 09, 2010 1:42:23 PM (GMT Standard Time, UTC+00:00)
Comments [16]  | 

















January, 2012 (1)
November, 2011 (4)
October, 2011 (1)
September, 2011 (2)
August, 2011 (1)
July, 2011 (1)
May, 2011 (5)
March, 2011 (4)
February, 2011 (2)
January, 2011 (3)
November, 2010 (4)
October, 2010 (1)
September, 2010 (5)
August, 2010 (5)
July, 2010 (6)
June, 2010 (8)
May, 2010 (2)
April, 2010 (2)
January, 2010 (1)
December, 2009 (3)
November, 2009 (2)
October, 2009 (3)
September, 2009 (3)
August, 2009 (2)
July, 2009 (3)
May, 2009 (3)
April, 2009 (2)
March, 2009 (1)
February, 2009 (2)
January, 2009 (2)
December, 2008 (1)
November, 2008 (2)
October, 2008 (5)
September, 2008 (4)
August, 2008 (2)
July, 2008 (1)
June, 2008 (2)
May, 2008 (2)
April, 2008 (3)
February, 2008 (6)
January, 2008 (3)
December, 2007 (1)
November, 2007 (1)
October, 2007 (5)
September, 2007 (1)
July, 2007 (3)
June, 2007 (8)
April, 2007 (2)
March, 2007 (4)
February, 2007 (1)
December, 2006 (2)
November, 2006 (9)
October, 2006 (5)
September, 2006 (3)
August, 2006 (2)
July, 2006 (4)
June, 2006 (5)
May, 2006 (10)
April, 2006 (4)
March, 2006 (2)
February, 2006 (12)
January, 2006 (7)
December, 2005 (2)
November, 2005 (15)
October, 2005 (6)
September, 2005 (7)
August, 2005 (3)
July, 2005 (10)
June, 2005 (11)
May, 2005 (7)
April, 2005 (8)
March, 2005 (6)
February, 2005 (2)
January, 2005 (6)
December, 2004 (3)
November, 2004 (5)
October, 2004 (2)
September, 2004 (5)
August, 2004 (13)
July, 2004 (6)
June, 2004 (14)
May, 2004 (17)
April, 2004 (12)
March, 2004 (8)
February, 2004 (10)
January, 2004 (14)
December, 2003 (9)
November, 2003 (13)
October, 2003 (3)





Sign In
Copyright © 2006-2007 Brian Noyes. All rights reserved.

designed by NUKEATION STUDIOS