Nearly everything you’ll read about .NET licensing binds the licensing concept to controls, with the idea being control developers could ship controls that are licensed at design time and/or run time. As it happens, you can apply Framework licensing to any class derived from System.Windows.Forms.Control, which would include entire Windows Forms applications, but I’ll begin with controls themselves. The basic control licensing UML static class diagram is shown in Figure 1.
Figure 1. .NET Control Licensing Static Class Diagram.
The general execution sequence is shown (as a UML sequence diagram) in Figure 2. The licensed control, in its constructor, requests a license from the LicenseManager:
license = LicenseManager.Validate(typeof(MyLicensedControl), this);
In this case, the constructor is for the licensed control as implemented in the class MyLicensedControl. Interestingly, there may be nothing more you need to do with the license object itself (it depends upon the implementation of the license), except to properly dispose of it as there may be resources attached. Out of the box, the important action we took was to call the license manager and ask for a license. If a license is not to be granted for some reason, the Validate() call will fail with an exception if exceptions are desired or return a null license if exceptions are to be suppressed. (The call to LicenseProvider.GetLicense() controls this, and the default Framework implementation is to allow exceptions.)