SimplCommerce icon indicating copy to clipboard operation
SimplCommerce copied to clipboard

Refactoring module loading (maybe just clarify)

Open RomanCharnashei opened this issue 3 years ago • 4 comments

I figured out a bit about loading modules here and in .NET Core in general. It seems to the flag IsBundledWithHost in current implementation redundant. There are currently two ways to load modules: Assembly.Load(new AssemblyName(module.Id)); and AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName); apparently implied that Assembly.Load if IsBundledWithHost set true and AssemblyLoadContext.Default.LoadFromAssemblyPath if set false. But from what I understand these two methods lead to the same result. They are all load plugins with dependence in default context i.e. AssemblyLoadContext.Default. https://github.com/richlander/dotnet-core-assembly-loading

Do I understand correctly that the code has not been completed yet ? If this part is already completed maybe it will be better to clean up the excess ? But maybe I'm wrong and I didn't understand something .

RomanCharnashei avatar Apr 10 '21 23:04 RomanCharnashei

Oh, It seems I got it, IsBundledWithHost mean that WebHost just has references on related modules. I understand correctly? In this case it seams to me it will be more convenient implement your own AssemblyLoadContext with AssemblyDependencyResolver in case when IsBundledWithHost is false i.e. outside of solution.

RomanCharnashei avatar Apr 11 '21 18:04 RomanCharnashei

I think you right. And I think in the case IsBundledWithHost is false, you must publish your module to folder and locate it in Modules folder to try load it. But when I try to publish a module, it product nugetpackage => so I think it cannot to use this feature now, otherwise find solution to publish it as DLL.

nqtuyen avatar Jun 06 '21 02:06 nqtuyen

I think you right. And I think in the case IsBundledWithHost is false, you must publish your module to folder and locate it in Modules folder to try load it. But when I try to publish a module, it product nugetpackage => so I think it cannot to use this feature now, otherwise find solution to publish it as DLL.

yes, DLL is exactly what I meant, like a plugin system I think now there are no obstacles to publich modules as DLL and most likely it will be quite easy to make a plugin system on this project

RomanCharnashei avatar Jun 07 '21 00:06 RomanCharnashei

Yes, you are. pls take a look at: https://docs.simplcommerce.com/developer-guide/how-to-add-new-modules.html Hope to help you!

nqtuyen avatar Jun 08 '21 13:06 nqtuyen