From 9404310e609d2c7d5c66ba14081a236995f6c745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 3 Jan 2017 22:21:02 +0300 Subject: [PATCH] Added a test plugin. --- Volo.Abp.sln | 7 ++++++ .../AbpDesk/ConsoleDemo/Program.cs | 24 +++++++++++++++++- .../AbpDesk.SamplePlugInModule.xproj | 21 ++++++++++++++++ .../AbpDeskSamplePlugInModule.cs | 17 +++++++++++++ .../Properties/AssemblyInfo.cs | 19 ++++++++++++++ .../AbpDesk.SamplePlugInModule/project.json | 14 +++++++++++ .../Modularity/PlugIns/FolderPlugInSource.cs | 25 ++++++++++++++++--- .../PlugIns/PlugInSourceListExtensions.cs | 9 +++++-- .../Volo/Abp/Reflection/AssemblyHelper.cs | 15 ++++++----- 9 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj create mode 100644 src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDeskSamplePlugInModule.cs create mode 100644 src/AbpDesk/AbpDesk.SamplePlugInModule/Properties/AssemblyInfo.cs create mode 100644 src/AbpDesk/AbpDesk.SamplePlugInModule/project.json diff --git a/Volo.Abp.sln b/Volo.Abp.sln index 0ee3939ae5..6423a9cd4e 100644 --- a/Volo.Abp.sln +++ b/Volo.Abp.sln @@ -88,6 +88,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.MongoDB", "src\Vol EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AbpDesk.MongoBlog", "src\AbpDesk\AbpDesk.MongoBlog\AbpDesk.MongoBlog.xproj", "{63244DC7-34BE-44E1-BF6F-F2672E59AF36}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AbpDesk.SamplePlugInModule", "src\AbpDesk\AbpDesk.SamplePlugInModule\AbpDesk.SamplePlugInModule.xproj", "{ADFAF85B-B785-41EA-B57D-422775989FA6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -214,6 +216,10 @@ Global {63244DC7-34BE-44E1-BF6F-F2672E59AF36}.Debug|Any CPU.Build.0 = Debug|Any CPU {63244DC7-34BE-44E1-BF6F-F2672E59AF36}.Release|Any CPU.ActiveCfg = Release|Any CPU {63244DC7-34BE-44E1-BF6F-F2672E59AF36}.Release|Any CPU.Build.0 = Release|Any CPU + {ADFAF85B-B785-41EA-B57D-422775989FA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADFAF85B-B785-41EA-B57D-422775989FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADFAF85B-B785-41EA-B57D-422775989FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADFAF85B-B785-41EA-B57D-422775989FA6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -257,5 +263,6 @@ Global {4AB91077-82DC-4335-9274-BCE017BD9C8B} = {146F561E-C7B8-4166-9383-47E1BC1A2E62} {B31FFAE3-5DAC-4E51-BD17-F7446B741A36} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} {63244DC7-34BE-44E1-BF6F-F2672E59AF36} = {1187F469-0063-4065-9419-A1D956C80145} + {ADFAF85B-B785-41EA-B57D-422775989FA6} = {1187F469-0063-4065-9419-A1D956C80145} EndGlobalSection EndGlobal diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs index dc9a9e665f..45555e2303 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs @@ -1,6 +1,8 @@ using System; +using System.IO; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; +using Volo.Abp.Modularity.PlugIns; namespace AbpDesk.ConsoleDemo { @@ -9,7 +11,12 @@ namespace AbpDesk.ConsoleDemo public static void Main(string[] args) { var services = new ServiceCollection(); - var application = services.AddApplication(); + + var application = services.AddApplication(options => + { + AddPlugIns(options); + }); + using (var scope = services.BuildServiceProvider().CreateScope()) { application.Initialize(scope.ServiceProvider); @@ -46,5 +53,20 @@ namespace AbpDesk.ConsoleDemo .GetRequiredService() .List(); } + + private static void AddPlugIns(AbpApplicationCreationOptions options) + { + options.PlugInSources.Add( + new FolderPlugInSource( + Path.Combine( + Directory.GetCurrentDirectory(), + @"..\AbpDesk.SamplePlugInModule\bin\Debug\netstandard1.6\" + ) + ) + { + Filter = filePath => filePath.EndsWith("AbpDesk.SamplePlugInModule.dll") + } + ); + } } } diff --git a/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj b/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj new file mode 100644 index 0000000000..cea27bbf28 --- /dev/null +++ b/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + adfaf85b-b785-41ea-b57d-422775989fa6 + AbpDesk.SamplePlugInModule + .\obj + .\bin\ + v4.6.1 + + + + 2.0 + + + diff --git a/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDeskSamplePlugInModule.cs b/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDeskSamplePlugInModule.cs new file mode 100644 index 0000000000..57f2f32ea3 --- /dev/null +++ b/src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDeskSamplePlugInModule.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace AbpDesk.SamplePlugInModule +{ + /* This is just a sample plugin module to test loading plugin modules. + */ + + public class AbpDeskSamplePlugInModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + + } + } +} diff --git a/src/AbpDesk/AbpDesk.SamplePlugInModule/Properties/AssemblyInfo.cs b/src/AbpDesk/AbpDesk.SamplePlugInModule/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..1323b1118e --- /dev/null +++ b/src/AbpDesk/AbpDesk.SamplePlugInModule/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AbpDesk.SamplePlugInModule")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("adfaf85b-b785-41ea-b57d-422775989fa6")] diff --git a/src/AbpDesk/AbpDesk.SamplePlugInModule/project.json b/src/AbpDesk/AbpDesk.SamplePlugInModule/project.json new file mode 100644 index 0000000000..863659ace7 --- /dev/null +++ b/src/AbpDesk/AbpDesk.SamplePlugInModule/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.1", + "Volo.Abp": "1.0.0-*" + }, + + "frameworks": { + "netstandard1.6": { + "imports": "dnxcore50" + } + } +} diff --git a/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs b/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs index e0b22741ac..043f552593 100644 --- a/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs +++ b/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Loader; using JetBrains.Annotations; using Volo.Abp.Reflection; using Volo.ExtensionMethods.Collections.Generic; @@ -13,7 +16,11 @@ namespace Volo.Abp.Modularity.PlugIns public SearchOption SearchOption { get; set; } - public FolderPlugInSource([NotNull] string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly) + public Func Filter { get; set; } + + public FolderPlugInSource( + [NotNull] string folder, + SearchOption searchOption = SearchOption.TopDirectoryOnly) { Check.NotNull(folder, nameof(folder)); @@ -21,13 +28,11 @@ namespace Volo.Abp.Modularity.PlugIns SearchOption = searchOption; } - [NotNull] public Type[] GetModules() { var modules = new List(); - var assemblies = AssemblyHelper.GetAllAssembliesInFolder(Folder, SearchOption); - foreach (var assembly in assemblies) + foreach (var assembly in GetAssemblies()) { try { @@ -47,5 +52,17 @@ namespace Volo.Abp.Modularity.PlugIns return modules.ToArray(); } + + private IEnumerable GetAssemblies() + { + var assemblyFiles = AssemblyHelper.GetAssemblyFiles(Folder, SearchOption); + + if (Filter != null) + { + assemblyFiles = assemblyFiles.Where(Filter); + } + + return assemblyFiles.Select(AssemblyLoadContext.Default.LoadFromAssemblyPath); + } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/PlugInSourceListExtensions.cs b/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/PlugInSourceListExtensions.cs index 2dbf094b06..af6cb0c39b 100644 --- a/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/PlugInSourceListExtensions.cs +++ b/src/Volo.Abp/Volo/Abp/Modularity/PlugIns/PlugInSourceListExtensions.cs @@ -6,14 +6,19 @@ namespace Volo.Abp.Modularity.PlugIns { public static class PlugInSourceListExtensions { - public static void AddFolder([NotNull] this PlugInSourceList list, [NotNull] string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly) + public static void AddFolder( + [NotNull] this PlugInSourceList list, + [NotNull] string folder, + SearchOption searchOption = SearchOption.TopDirectoryOnly) { Check.NotNull(list, nameof(list)); list.Add(new FolderPlugInSource(folder, searchOption)); } - public static void AddTypes([NotNull] this PlugInSourceList list, params Type[] moduleTypes) + public static void AddTypes( + [NotNull] this PlugInSourceList list, + params Type[] moduleTypes) { Check.NotNull(list, nameof(list)); diff --git a/src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs b/src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs index ed3c7cb54a..6247095b3d 100644 --- a/src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs +++ b/src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs @@ -8,15 +8,18 @@ namespace Volo.Abp.Reflection { internal static class AssemblyHelper { - public static List GetAllAssembliesInFolder(string folderPath, SearchOption searchOption) + public static List LoadAssemblies(string folderPath, SearchOption searchOption) { - var assemblyFiles = Directory + return GetAssemblyFiles(folderPath, searchOption) + .Select(AssemblyLoadContext.Default.LoadFromAssemblyPath) + .ToList(); + } + + public static IEnumerable GetAssemblyFiles(string folderPath, SearchOption searchOption) + { + return Directory .EnumerateFiles(folderPath, "*.*", searchOption) .Where(s => s.EndsWith(".dll") || s.EndsWith(".exe")); - - //TODO: AssemblyLoadContext not tested - - return assemblyFiles.Select(AssemblyLoadContext.Default.LoadFromAssemblyPath).ToList(); } } }