Link your License to your Project

◷ Reading Time: 2 minutes

To link your license to your project, you need to use an assembly attribute:

[assembly: FlexRule.License.LicenseProvider(A_PROVIDER_TYPE)]

The A_PROVIDER_TYPE can be a default file-based which reads your license file or can be your custom type.

Default location

To let your application read the license, simply add below code to your project:

[assembly: FlexRule.License.LicenseProvider(typeof(FlexRule.License.FileBasedLicenseProvider))]

This enables FlexRule Runtime to read the FlexRule.License.lic file from the current location. The current location is where your application exec file exists. Or if your application is a web application, web API and etc, it will be the bin folder of the project.

Embedding License

You also can embed the license into your project. In order to do that, you can simply use the technique that we previously mentioned concerning the custom location for the license file.

Or add a file named FlexRuleLicenseProvider.cs to your project and copy the code below:

using System;
using System.IO;
using FlexRule.License;
 
[assembly: LicenseProvider(typeof(MyLicenseProvider))]
 
namespace MyCompany.MyApp
{
    /// <summary>
    /// This class reads the license file for the project
    /// </summary>
    public class MyLicenseProvider : ILicenseProvider
    {
        public string ReadLicense()
        {
            string yourLicense="..."; // replace ... with your license content
            return yourLicense;
        }
    }
}

Initializing License

When a custom provider is defined, for initializing your license, simply call the default override with no parameters:

UserLicense.Initialize()
Updated on April 17, 2020

Was this article helpful?

Related Articles