Browse Source

Added a test plugin.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
9404310e60
  1. 7
      Volo.Abp.sln
  2. 24
      src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
  3. 21
      src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj
  4. 17
      src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDeskSamplePlugInModule.cs
  5. 19
      src/AbpDesk/AbpDesk.SamplePlugInModule/Properties/AssemblyInfo.cs
  6. 14
      src/AbpDesk/AbpDesk.SamplePlugInModule/project.json
  7. 25
      src/Volo.Abp/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs
  8. 9
      src/Volo.Abp/Volo/Abp/Modularity/PlugIns/PlugInSourceListExtensions.cs
  9. 15
      src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs

7
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

24
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<AbpDeskConsoleDemoModule>();
var application = services.AddApplication<AbpDeskConsoleDemoModule>(options =>
{
AddPlugIns(options);
});
using (var scope = services.BuildServiceProvider().CreateScope())
{
application.Initialize(scope.ServiceProvider);
@ -46,5 +53,20 @@ namespace AbpDesk.ConsoleDemo
.GetRequiredService<BlogPostLister>()
.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")
}
);
}
}
}

21
src/AbpDesk/AbpDesk.SamplePlugInModule/AbpDesk.SamplePlugInModule.xproj

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>adfaf85b-b785-41ea-b57d-422775989fa6</ProjectGuid>
<RootNamespace>AbpDesk.SamplePlugInModule</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

17
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)
{
}
}
}

19
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")]

14
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"
}
}
}

25
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<string, bool> 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<Type>();
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<Assembly> GetAssemblies()
{
var assemblyFiles = AssemblyHelper.GetAssemblyFiles(Folder, SearchOption);
if (Filter != null)
{
assemblyFiles = assemblyFiles.Where(Filter);
}
return assemblyFiles.Select(AssemblyLoadContext.Default.LoadFromAssemblyPath);
}
}
}

9
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));

15
src/Volo.Abp/Volo/Abp/Reflection/AssemblyHelper.cs

@ -8,15 +8,18 @@ namespace Volo.Abp.Reflection
{
internal static class AssemblyHelper
{
public static List<Assembly> GetAllAssembliesInFolder(string folderPath, SearchOption searchOption)
public static List<Assembly> LoadAssemblies(string folderPath, SearchOption searchOption)
{
var assemblyFiles = Directory
return GetAssemblyFiles(folderPath, searchOption)
.Select(AssemblyLoadContext.Default.LoadFromAssemblyPath)
.ToList();
}
public static IEnumerable<string> 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();
}
}
}

Loading…
Cancel
Save