Open Closed

Module as a plugin in a tiered application #5937


User avatar
0
cxp920 created
  • ABP Framework version: v7.3.2
  • UI Type: MVC
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

Hi,

I have a tiered application that loads a plugin module called TestModule (created via ABP Suite) in the Program.cs file of the ApiHost and Web projects using the following code:

await builder.AddApplicationAsync<ABPHttpApiHostModule>(options =>
            {
                var env = builder.Environment;
                if (env.IsDevelopment())
                {
                    var path = builder.Configuration.GetValue<string>("PluginsFolderLocalPath");
                    options.PlugInSources.AddFolder(path, SearchOption.AllDirectories);
                }
                else
                {
                    options.PlugInSources.AddFolder(config.Value, SearchOption.AllDirectories);
                }
            });

I also have a separate module called Shared that I use as a nuget package and it is intalled in my plugin module (each project is intalled in the corresponding project in the plugin module, meaning Shared.Application is installed in TestModule.Application, Shared.Application.Contracts is installed in TestModule.Application.Contracts, and so on). These nugets are also installed in the main application in their corresponding project.

The problem is that when running ApiHost, I get the following error:

Host terminated unexpectedly!
System.IO.FileNotFoundException: Could not load file or assembly 'Shared.Application.Contracts, Version=0.4.73.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Shared.Application.Contracts, Version=0.4.73.0, Culture=neutral, PublicKeyToken=null'

If I install Shared.Application.Contracts in ApiHost, this problem disappears and it asks for another package from the Shared project, and so on until most Shared packages are installed in ApiHost. The same issue happens next when running Web.

It seems that by adding a plugin module, the main project does not have access to the dependencies of the module's projects (.dlls).

The documentation on Plugin Modules is very limited. The example given consists on adding a single .dll file as a plugin. I am adding a full module project as 8 .dlls. Is there anything I am missing to make this work? Specifically, I would like to know how to properly add a module as a plugin in a tiered application with other modules as nuget package dependencies.


3 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello cxp920,

    I am trying to reproduce the issue at my end with your code but I am not getting that error.

    I made some changes in your code as below and it works fine at my end.

            await builder.AddApplicationAsync<Demo5937WebModule>(options =>
            {
                    var env = builder.Environment;
                    if (env.IsDevelopment())
                    {
                        var pathSection = builder.Configuration.GetSection("PluginsFolderLocalPath");
                        var path = pathSection.Exists() ? pathSection.Value : null;
                        if (path != null)
                        {
                            options.PlugInSources.AddFolder(path, SearchOption.AllDirectories);
                        }
                    }
                    else
                    {
                        var configSection = builder.Configuration.GetSection("YourConfigKey"); // Replace with your actual configuration key
                        var configValue = configSection.Exists() ? configSection.Value : null;
                        if (configValue != null)
                        {
                            options.PlugInSources.AddFolder(configValue, SearchOption.AllDirectories);
                        }
                    }
                });
    

    could you please check with this code?

    Please do let me know if it helps you.

    Thank you, Anjali

  • User Avatar
    0
    cxp920 created

    Hi Anjali,

    Thank you for your prompt response.

    The issue happens when I install the module Shared as nuget packages in my plugin module. Were you able to reproduce this scenario? Meaning installing an ABP module (created via ABP Suite) that was transformed into nuget packages into a plugin module, then loading that plugin module in Host.

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello cxp920,

    I have tried to do so by following below documentation at my end and its working fine. Could please check once the documentation and also the video link. https://docs.abp.io/en/abp/latest/Module-Development-Basics https://www.youtube.com/watch?v=WVKHfYxezNo

    please let me know if it helps you

    Thank you, Anjali

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11