> For the complete documentation index, see [llms.txt](https://m-ahmed310.gitbook.io/fignet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://m-ahmed310.gitbook.io/fignet/core-concepts/modules.md).

# Modules

`In FigNet Modules implement FigNet.Core.IModule & it is used to add your custom logic to fignet application as a plugin.`

```csharp
//IModule
namespace FigNet.Core
{
    public interface IModule
    {
        void Load(IServer server);
        void Process(float deltaTime);  // gets call per frame
        void UnLoad();
    }
}
```

### How to create a Module

```csharp
public class TestModule : IModule
{
     // here define your properties & logic
     public void Load(IServer server)
      {
          FN.Logger.Info("test loaded");
          FN.HandlerCollection.RegisterHandler(new TestHandler());
      }
 
      public void Process(float deltaTime)
      {
      }
 
      public void UnLoad()
      {   
      }
}
```

### How to load a Module

`Open ServerConfig.xml and add Module tag and under that tag add assemblyName & Type tags AssemblyName is the name of the dll or solution whereas Type name is the class name including namespace.`

```markup
<Modules>
      <Module>
        <AssemblyName>FigNetTemplate</AssemblyName>
        <Type>FigNetTemplate.Modules.FolderName.TestModule</Type>
        <Dependencies>
          <Package>
            <AssemblyName>LiteNetLib</AssemblyName>
          </Package>
        </Dependencies>
       </Module>
</Modules>
```

| Tag          | Description                                 |
| ------------ | ------------------------------------------- |
| Module       | define an instance of module                |
| AssemblyName | assembly name (dll) without extension       |
| Type         | name of module including complete namespace |
| Dependencies | addition assemblies a module depends on     |
| Package      | dependency                                  |

{% hint style="info" %}
Modules use reflection to create instances if you are using Unity IL2CPP load module manually instead of using config.
{% endhint %}

### How to manually load the module&#x20;

```csharp
static void Main(string[] args)
{
    IServer serverApp = new ServerApplication();
    serverApp.SetUp();
    serverApp.AddModule(new TestModule());
    Run(serverApp);
    serverApp.TearDown();
}
```

{% hint style="info" %}
AddModule method also calls the Load method of Module internally. There is no need to call Load method of Module explicitly&#x20;
{% endhint %}
