<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Executing Code Before Plugin Initialization</title><link>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Executing Code Before Plugin Initialization</title><link>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization</link><pubDate>Tue, 04 Aug 2020 21:34:24 GMT</pubDate><guid isPermaLink="false">10dc7ed0-089d-4767-892a-2f5a479beb38</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/04/2020 21:34:24&lt;br /&gt;
&lt;p&gt;The &lt;strong&gt;IBeforeInitializationPlugin&lt;/strong&gt; is a plugin that allows you to execute code after plugins are instantiated but before plugins initialize.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="What_would_I_use_IBeforeInitializationPlugin_for" name="What_would_I_use_IBeforeInitializationPlugin_for"&gt;&lt;/a&gt;What would I use IBeforeInitializationPlugin for?&lt;/h2&gt;
&lt;p&gt;This plugin is useful anytime you have something that needs to be available to all your custom plugins before they initialize. &amp;nbsp;This could be something as simple as a global variable. &amp;nbsp;More commonly it is useful if you are using a Dependency Injection framework(referred to later as a DI Framework) and you must bind your services. &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Required Platform DLL References:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Telligent.Evolution.Platform.dll&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Plugin_Lifecycle" name="Plugin_Lifecycle"&gt;&lt;/a&gt;Plugin Lifecycle&lt;/h2&gt;
&lt;p&gt;If you are not already you should familiarize&amp;nbsp;yourself with the [[Plugin Lifecycle]]. &amp;nbsp;&lt;code&gt;IBeforeInitializationPlugins&lt;/code&gt; will execute after enabled plugins are instantiated and configured and before Apis are registered. &amp;nbsp;This means any&amp;nbsp;global variables (assuming static variables assigned a value or variables in the proper scope) or bound services from&amp;nbsp;for your DI framework will be available in an &lt;code&gt;IApiDefinition&lt;/code&gt; plugin if you are using one or if not in a plugin&amp;#39;s&lt;code&gt; Initialize()&lt;/code&gt; method and later. &amp;nbsp;These would not be available for use when &lt;code&gt;IRecurringEvolutionJobs&lt;/code&gt; register their default schedules or context, &lt;code&gt;IConfigurablePlugins&lt;/code&gt; define configuration, or &lt;code&gt;ITranslatablePlugins&lt;/code&gt; register their translations. &amp;nbsp; Platform In-Process Apis are also not available during the before initialization process.&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;a href="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png"&gt;&lt;img alt=" " src="/resized-image/__size/1040x0/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_an_IBeforeInitializationPlugin" name="Creating_an_IBeforeInitializationPlugin"&gt;&lt;/a&gt;Creating an IBeforeInitializationPlugin&lt;/h2&gt;
&lt;p&gt;An &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; in addition to the normal IPlugin members only have a single method, &lt;code&gt;BeforeInitialization&lt;/code&gt; receiving a &lt;code&gt;BeforeInitializationArguments&lt;/code&gt; object. &amp;nbsp; This plugin is slightly different than most others in the sense that is written like&amp;nbsp;its an Event handler, though it is not a true event. &amp;nbsp;Instead the &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; is a normal&amp;nbsp;method invoked by the platform before plugin initialization.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public interface IBeforeInitializationPlugin:IPlugin
{
    void BeforeInitialize(BeforeInitializationArguments args);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&lt;strong&gt;BeforeInitializationArguments&lt;/strong&gt;&lt;/code&gt; exposes&amp;nbsp;an enumeration called &lt;code&gt;&lt;strong&gt;PluginInitializationReason&lt;/strong&gt;&lt;/code&gt; that allows you to determine why plugins are being re-initialized. &amp;nbsp;Currently there are 2 reasons plugins will re-initialize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.AppStart&lt;/strong&gt; - &amp;nbsp;Happens when plugins initialize because the application itself is starting or re-starting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.PluginReload&lt;/strong&gt; - Happens whenever a plugin or plugins are saved and/or enabled or disabled. &amp;nbsp; This is not just your plugin, it is any plugin currently installed in your community.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Service_Binding_Example" name="Service_Binding_Example"&gt;&lt;/a&gt;Service Binding Example&lt;/h3&gt;
&lt;p&gt;First, this is not meant to be a source on how to use a dependency injection framework nor are we going to illustrate using any specific one. &amp;nbsp; For this example we will simply show a flow that is common for many using a simulated container. &amp;nbsp; You should consult your specific framework&amp;#39;s documentation on usage and to evaluate its appropriateness for use in this particular implementation.&lt;/p&gt;
&lt;p&gt;First create your plugin and have it implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp;You will notice the standard IPlugin members(omitted below for brevity) and the additional &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; member specific to this plugin. &amp;nbsp;Its here that we will add our service binding logic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public class BeforeInitializationPlugin : IBeforeInitializationPlugin
{
    #region IPlugin Members
     
    public void BeforeInitialize(BeforeInitializationArguments args){ }
     
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In our example the &amp;quot;Container&amp;quot; class is a simulated DI framework collection of service bindings. Consult your frameworks documentation for its specific way of doing service bindings.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the sample we want to evaluate 2 conditions when deciding to bind our services. &amp;nbsp;The most important thing to remember this will only ever run when you enable the plugin so you can be assured if this executes, your plugin is enabled. &amp;nbsp; You will want to run this when the application starts OR if the container is not bound or initialized. &amp;nbsp; You need to check that it&amp;#39;s initialized because at some point your plugin will be manually enabled and you will want to bind your services immediately, not wait for the next reload or application start. &amp;nbsp; Again checking if a container in a specific framework can vary by framework so refer to the documentation. &amp;nbsp; Our sample has an &lt;code&gt;IsInitialized&lt;/code&gt; member.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void BeforeInitialize(BeforeInitializationArguments args)
{
     //This runs before any plugin intializes
     if (args.Reason == PluginInitializationReason.AppStart || !Container.IsInitialized)
     {
         Container.Register&amp;lt;ISampleService&amp;gt;(new SomeSampleService());
     }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Depending on your code or framework, it may suffice to only check for the container being initialized or bound since realistically on application start it will not be. &amp;nbsp;But the option to determine application start specifically is available and is shown here for example purposes if you should need to use it. &amp;nbsp;The actual line of code in the sample doing the binding is not relevant to the overall purpose of the example as its syntax will vary by framework.&lt;/p&gt;
&lt;p&gt;You can test that it all works and that your services are available in the initialization method of the plugin by attempting to retrieve a service from your container. &amp;nbsp; This example uses our sample DI framework to get a service and invoke a member and outputting the value to the event log.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void Initialize()
{
    var service = Container.Get&amp;lt;ISampleService&amp;gt;(); //My service will be available
    Apis.Get&amp;lt;IEventLog&amp;gt;().Write(service.SayHello(), new EventLogEntryWriteOptions());
}&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Considerations" name="Considerations"&gt;&lt;/a&gt;Considerations&lt;/h2&gt;
&lt;p&gt;If you are writing a simple plugin that needs to utilize before initialization functionality, you can simply extend your existing plugin with &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp; If you have multiple plugins that all depend on before initialization logic it is&amp;nbsp;recommended &amp;nbsp;to use a [[Managing Dependencies|plugin group]]&amp;nbsp;with either an implementation of &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; included in the group, or the plugin group could implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; itself.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Source" name="Source"&gt;&lt;/a&gt;Source&lt;/h2&gt;
&lt;p&gt;This is &amp;nbsp;the full source of the example used in this article. &amp;nbsp;You can add it to a project, compile it and deploy it to your Verint Community. &amp;nbsp; After enabling the &amp;quot;BeforeInitializationPlugin Sample&amp;quot; plugin under the Extensions menu in Administration, you should see &amp;quot;Hello&amp;quot; in the event log under the monitoring menu. &amp;nbsp;It will re-appear if you recycle the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/4478_2E00_BeforeInitializationPlugin_2E00_cs"&gt;community.telligent.com/.../4478_2E00_BeforeInitializationPlugin_2E00_cs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: IBeforeInitializationPlugin&lt;/div&gt;
</description></item><item><title>Executing Code Before Plugin Initialization</title><link>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization/revision/2</link><pubDate>Tue, 04 Aug 2020 21:30:29 GMT</pubDate><guid isPermaLink="false">10dc7ed0-089d-4767-892a-2f5a479beb38</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization#comments</comments><description>Revision 2 posted to Developer Training by Former Member on 08/04/2020 21:30:29&lt;br /&gt;
&lt;p&gt;The &lt;strong&gt;IBeforeInitializationPlugin&lt;/strong&gt; is a plugin that allows you to execute code after plugins are instantiated but before plugins initialize.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="What_would_I_use_IBeforeInitializationPlugin_for" name="What_would_I_use_IBeforeInitializationPlugin_for"&gt;&lt;/a&gt;What would I use IBeforeInitializationPlugin for?&lt;/h2&gt;
&lt;p&gt;This plugin is useful anytime you have something that needs to be available to all your custom plugins before they initialize. &amp;nbsp;This could be something as simple as a global variable. &amp;nbsp;More commonly it is useful if you are using a Dependency Injection framework(referred to later as a DI Framework) and you must bind your services. &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Required Platform DLL References:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Telligent.Evolution.Platform.dll&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Plugin_Lifecycle" name="Plugin_Lifecycle"&gt;&lt;/a&gt;Plugin Lifecycle&lt;/h2&gt;
&lt;p&gt;If you are not already you should familiarize&amp;nbsp;yourself with the [[Plugin Lifecycle]]. &amp;nbsp;&lt;code&gt;IBeforeInitializationPlugins&lt;/code&gt; will execute after enabled plugins are instantiated and configured and before Apis are registered. &amp;nbsp;This means any&amp;nbsp;global variables (assuming static variables assigned a value or variables in the proper scope) or bound services from&amp;nbsp;for your DI framework will be available in an &lt;code&gt;IApiDefinition&lt;/code&gt; plugin if you are using one or if not in a plugin&amp;#39;s&lt;code&gt; Initialize()&lt;/code&gt; method and later. &amp;nbsp;These would not be available for use when &lt;code&gt;IRecurringEvolutionJobs&lt;/code&gt; register their default schedules or context, &lt;code&gt;IConfigurablePlugins&lt;/code&gt; define configuration, or &lt;code&gt;ITranslatablePlugins&lt;/code&gt; register their translations. &amp;nbsp; Platform In-Process Apis are also not available during the before initialization process.&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;a href="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png"&gt;&lt;img alt=" " src="/resized-image/__size/1040x0/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_an_IBeforeInitializationPlugin" name="Creating_an_IBeforeInitializationPlugin"&gt;&lt;/a&gt;Creating an IBeforeInitializationPlugin&lt;/h2&gt;
&lt;p&gt;An &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; in addition to the normal IPlugin members only have a single method, &lt;code&gt;BeforeInitialization&lt;/code&gt; receiving a &lt;code&gt;BeforeInitializationArguments&lt;/code&gt; object. &amp;nbsp; This plugin is slightly different than most others in the sense that is written like&amp;nbsp;its an Event handler, though it is not a true event. &amp;nbsp;Instead the &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; is a normal&amp;nbsp;method invoked by the platform before plugin initialization.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public interface IBeforeInitializationPlugin:IPlugin
{
    void BeforeInitialize(BeforeInitializationArguments args);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&lt;strong&gt;BeforeInitializationArguments&lt;/strong&gt;&lt;/code&gt; exposes&amp;nbsp;an enumeration called &lt;code&gt;&lt;strong&gt;PluginInitializationReason&lt;/strong&gt;&lt;/code&gt; that allows you to determine why plugins are being re-initialized. &amp;nbsp;Currently there are 2 reasons plugins will re-initialize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.AppStart&lt;/strong&gt; - &amp;nbsp;Happens when plugins initialize because the application itself is starting or re-starting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.PluginReload&lt;/strong&gt; - Happens whenever a plugin or plugins are saved and/or enabled or disabled. &amp;nbsp; This is not just your plugin, it is any plugin currently installed in your community.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Service_Binding_Example" name="Service_Binding_Example"&gt;&lt;/a&gt;Service Binding Example&lt;/h3&gt;
&lt;p&gt;First, this is not meant to be a source on how to use a dependency injection framework nor are we going to illustrate using any specific one. &amp;nbsp; For this example we will simply show a flow that is common for many using a simulated container. &amp;nbsp; You should consult your specific framework&amp;#39;s documentation on usage and to evaluate its appropriateness for use in this particular implementation.&lt;/p&gt;
&lt;p&gt;First create your plugin and have it implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp;You will notice the standard IPlugin members(omitted below for brevity) and the additional &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; member specific to this plugin. &amp;nbsp;Its here that we will add our service binding logic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public class BeforeInitializationPlugin : IBeforeInitializationPlugin
{
    #region IPlugin Members
     
    public void BeforeInitialize(BeforeInitializationArguments args){ }
     
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In our example the &amp;quot;Container&amp;quot; class is a simulated DI framework collection of service bindings. Consult your frameworks documentation for its specific way of doing service bindings.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the sample we want to evaluate 2 conditions when deciding to bind our services. &amp;nbsp;The most important thing to remember this will only ever run when you enable the plugin so you can be assured if this executes, your plugin is enabled. &amp;nbsp; You will want to run this when the application starts OR if the container is not bound or initialized. &amp;nbsp; You need to check that it&amp;#39;s initialized because at some point your plugin will be manually enabled and you will want to bind your services immediately, not wait for the next reload or application start. &amp;nbsp; Again checking if a container in a specific framework can vary by framework so refer to the documentation. &amp;nbsp; Our sample has an &lt;code&gt;IsInitialized&lt;/code&gt; member.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void BeforeInitialize(BeforeInitializationArguments args)
{
     //This runs before any plugin intializes
     if (args.Reason == PluginInitializationReason.AppStart || !Container.IsInitialized)
     {
         Container.Register&amp;lt;ISampleService&amp;gt;(new SomeSampleService());
     }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Depending on your code or framework, it may suffice to only check for the container being initialized or bound since realistically on application start it will not be. &amp;nbsp;But the option to determine application start specifically is available and is shown here for example purposes if you should need to use it. &amp;nbsp;The actual line of code in the sample doing the binding is not relevant to the overall purpose of the example as its syntax will vary by framework.&lt;/p&gt;
&lt;p&gt;You can test that it all works and that your services are available in the initialization method of the plugin by attempting to retrieve a service from your container. &amp;nbsp; This example uses our sample DI framework to get a service and invoke a member and outputting the value to the event log.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void Initialize()
{
    var service = Container.Get&amp;lt;ISampleService&amp;gt;(); //My service will be available
    Apis.Get&amp;lt;IEventLog&amp;gt;().Write(service.SayHello(), new EventLogEntryWriteOptions());
}&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Considerations" name="Considerations"&gt;&lt;/a&gt;Considerations&lt;/h2&gt;
&lt;p&gt;If you are writing a simple plugin that needs to utilize before initialization functionality, you can simply extend your existing plugin with &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp; If you have multiple plugins that all depend on before initialization logic it is&amp;nbsp;recommended &amp;nbsp;to use a [[Managing Dependencies|plugin group]]&amp;nbsp;with either an implementation of &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; included in the group, or the plugin group could implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; itself.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Source" name="Source"&gt;&lt;/a&gt;Source&lt;/h2&gt;
&lt;p&gt;This is &amp;nbsp;the full source of the example used in this article. &amp;nbsp;You can add it to a project, compile it and deploy it to your Verint Community. &amp;nbsp; After enabling the &amp;quot;BeforeInitializationPlugin Sample&amp;quot; plugin under the Extensions menu in Administration, you should see &amp;quot;Hello&amp;quot; in the event log under the monitoring menu. &amp;nbsp;It will re-appear if you recycle the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/4478_2E00_BeforeInitializationPlugin_2E00_cs"&gt;community.telligent.com/.../4478_2E00_BeforeInitializationPlugin_2E00_cs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Executing Code Before Plugin Initialization</title><link>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization/revision/1</link><pubDate>Thu, 13 Jun 2019 19:28:42 GMT</pubDate><guid isPermaLink="false">10dc7ed0-089d-4767-892a-2f5a479beb38</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65111/executing-code-before-plugin-initialization#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/13/2019 19:28:42&lt;br /&gt;
&lt;p&gt;The &lt;strong&gt;IBeforeInitializationPlugin&lt;/strong&gt; is a plugin that allows you to execute code after plugins are instantiated but before plugins initialize.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="What_would_I_use_IBeforeInitializationPlugin_for" name="What_would_I_use_IBeforeInitializationPlugin_for"&gt;&lt;/a&gt;What would I use IBeforeInitializationPlugin for?&lt;/h2&gt;
&lt;p&gt;This plugin is useful anytime you have something that needs to be available to all your custom plugins before they initialize. &amp;nbsp;This could be something as simple as a global variable. &amp;nbsp;More commonly it is useful if you are using a Dependency Injection framework(referred to later as a DI Framework) and you must bind your services. &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Required Platform DLL References:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Telligent.Evolution.Platform.dll&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Plugin_Lifecycle" name="Plugin_Lifecycle"&gt;&lt;/a&gt;Plugin Lifecycle&lt;/h2&gt;
&lt;p&gt;If you are not already you should familiarize&amp;nbsp;yourself with the [[Plugin Lifecycle]]. &amp;nbsp;&lt;code&gt;IBeforeInitializationPlugins&lt;/code&gt; will execute after enabled plugins are instantiated and configured and before Apis are registered. &amp;nbsp;This means any&amp;nbsp;global variables (assuming static variables assigned a value or variables in the proper scope) or bound services from&amp;nbsp;for your DI framework will be available in an &lt;code&gt;IApiDefinition&lt;/code&gt; plugin if you are using one or if not in a plugin&amp;#39;s&lt;code&gt; Initialize()&lt;/code&gt; method and later. &amp;nbsp;These would not be available for use when &lt;code&gt;IRecurringEvolutionJobs&lt;/code&gt; register their default schedules or context, &lt;code&gt;IConfigurablePlugins&lt;/code&gt; define configuration, or &lt;code&gt;ITranslatablePlugins&lt;/code&gt; register their translations. &amp;nbsp; Platform In-Process Apis are also not available during the before initialization process.&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;a href="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png"&gt;&lt;img src="/resized-image/__size/1040x0/__key/communityserver-wikis-components-files/00-00-00-12-83/3264.Plugin-lifecycle_2D00_1.png" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_an_IBeforeInitializationPlugin" name="Creating_an_IBeforeInitializationPlugin"&gt;&lt;/a&gt;Creating an IBeforeInitializationPlugin&lt;/h2&gt;
&lt;p&gt;An &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; in addition to the normal IPlugin members only have a single method, &lt;code&gt;BeforeInitialization&lt;/code&gt; receiving a &lt;code&gt;BeforeInitializationArguments&lt;/code&gt; object. &amp;nbsp; This plugin is slightly different than most others in the sense that is written like&amp;nbsp;its an Event handler, though it is not a true event. &amp;nbsp;Instead the &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; is a normal&amp;nbsp;method invoked by the platform before plugin initialization.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public interface IBeforeInitializationPlugin:IPlugin
{
    void BeforeInitialize(BeforeInitializationArguments args);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&lt;strong&gt;BeforeInitializationArguments&lt;/strong&gt;&lt;/code&gt; exposes&amp;nbsp;an enumeration called &lt;code&gt;&lt;strong&gt;PluginInitializationReason&lt;/strong&gt;&lt;/code&gt; that allows you to determine why plugins are being re-initialized. &amp;nbsp;Currently there are 2 reasons plugins will re-initialize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.AppStart&lt;/strong&gt; - &amp;nbsp;Happens when plugins initialize because the application itself is starting or re-starting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PluginInitializationReason.PluginReload&lt;/strong&gt; - Happens whenever a plugin or plugins are saved and/or enabled or disabled. &amp;nbsp; This is not just your plugin, it is any plugin currently installed in your community.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Service_Binding_Example" name="Service_Binding_Example"&gt;&lt;/a&gt;Service Binding Example&lt;/h3&gt;
&lt;p&gt;First, this is not meant to be a source on how to use a dependency injection framework nor are we going to illustrate using any specific one. &amp;nbsp; For this example we will simply show a flow that is common for many using a simulated container. &amp;nbsp; You should consult your specific framework&amp;#39;s documentation on usage and to evaluate its appropriateness for use in this particular implementation.&lt;/p&gt;
&lt;p&gt;First create your plugin and have it implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp;You will notice the standard IPlugin members(omitted below for brevity) and the additional &lt;code&gt;BeforeInitialization(...)&lt;/code&gt; member specific to this plugin. &amp;nbsp;Its here that we will add our service binding logic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public class BeforeInitializationPlugin : IBeforeInitializationPlugin
{
    #region IPlugin Members
     
    public void BeforeInitialize(BeforeInitializationArguments args){ }
     
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In our example the &amp;quot;Container&amp;quot; class is a simulated DI framework collection of service bindings. Consult your frameworks documentation for its specific way of doing service bindings.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the sample we want to evaluate 2 conditions when deciding to bind our services. &amp;nbsp;The most important thing to remember this will only ever run when you enable the plugin so you can be assured if this executes, your plugin is enabled. &amp;nbsp; You will want to run this when the application starts OR if the container is not bound or initialized. &amp;nbsp; You need to check that it&amp;#39;s initialized because at some point your plugin will be manually enabled and you will want to bind your services immediately, not wait for the next reload or application start. &amp;nbsp; Again checking if a container in a specific framework can vary by framework so refer to the documentation. &amp;nbsp; Our sample has an &lt;code&gt;IsInitialized&lt;/code&gt; member.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void BeforeInitialize(BeforeInitializationArguments args)
{
     //This runs before any plugin intializes
     if (args.Reason == PluginInitializationReason.AppStart || !Container.IsInitialized)
     {
         Container.Register&amp;lt;ISampleService&amp;gt;(new SomeSampleService());
     }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Depending on your code or framework, it may suffice to only check for the container being initialized or bound since realistically on application start it will not be. &amp;nbsp;But the option to determine application start specifically is available and is shown here for example purposes if you should need to use it. &amp;nbsp;The actual line of code in the sample doing the binding is not relevant to the overall purpose of the example as its syntax will vary by framework.&lt;/p&gt;
&lt;p&gt;You can test that it all works and that your services are available in the initialization method of the plugin by attempting to retrieve a service from your container. &amp;nbsp; This example uses our sample DI framework to get a service and invoke a member and outputting the value to the event log.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void Initialize()
{
    var service = Container.Get&amp;lt;ISampleService&amp;gt;(); //My service will be available
    Apis.Get&amp;lt;IEventLog&amp;gt;().Write(service.SayHello(), new EventLogEntryWriteOptions());
}&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Considerations" name="Considerations"&gt;&lt;/a&gt;Considerations&lt;/h2&gt;
&lt;p&gt;If you are writing a simple plugin that needs to utilize before initialization functionality, you can simply extend your existing plugin with &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt;. &amp;nbsp; If you have multiple plugins that all depend on before initialization logic it is&amp;nbsp;recommended &amp;nbsp;to use a [[Managing Dependencies|plugin group]]&amp;nbsp;with either an implementation of &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; included in the group, or the plugin group could implement &lt;code&gt;IBeforeInitializationPlugin&lt;/code&gt; itself.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Source" name="Source"&gt;&lt;/a&gt;Source&lt;/h2&gt;
&lt;p&gt;This is &amp;nbsp;the full source of the example used in this article. &amp;nbsp;You can add it to a project, compile it and deploy it to your Telligent Community. &amp;nbsp; After enabling the &amp;quot;BeforeInitializationPlugin Sample&amp;quot; plugin under the Extensions menu in Administration, you should see &amp;quot;Hello&amp;quot; in the event log under the monitoring menu. &amp;nbsp;It will re-appear if you recycle the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/4478_2E00_BeforeInitializationPlugin_2E00_cs"&gt;community.telligent.com/.../4478_2E00_BeforeInitializationPlugin_2E00_cs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>