# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://m-ahmed310.gitbook.io/fignet/core-concepts/modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
