Merge pull request #14 from geffzhang/master
fix : dynamic load assymbly
This commit is contained in:
commit
747dea0e7d
|
|
@ -82,6 +82,7 @@ If you feel that this project is helpful to you, please Star on the project, we
|
|||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="RestSharp" Version="106.4.2" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Core.Modules
|
||||
|
|
@ -30,7 +31,7 @@ namespace BotSharp.Core.Modules
|
|||
|
||||
this._modules = options.Modules
|
||||
.Select(s =>
|
||||
{
|
||||
{
|
||||
Type type = Type.GetType(s.Type);
|
||||
|
||||
if (type == null)
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Text;
|
||||
using Console = Colorful.Console;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class PlatformServiceCollectionExtensions
|
||||
public static class PlatformAssembyLoader
|
||||
{
|
||||
public static IServiceCollection AddPlatformEmulator(this IServiceCollection services, IConfiguration configuration, Action<Assembly> action)
|
||||
public static void LoadPlatformEmulatorAssemblies(IConfiguration configuration, Action<Assembly> action)
|
||||
{
|
||||
var platform = configuration.GetValue<string>("Platform");
|
||||
var platformAssemblyName = configuration.GetValue<string>("platformAssemblyName");
|
||||
|
|
@ -31,7 +32,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
var platformDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{platformAssemblyName}.dll");
|
||||
if (File.Exists(platformDllPath))
|
||||
{
|
||||
Assembly library = Assembly.LoadFile(platformDllPath);
|
||||
Assembly library = AssemblyLoadContext.Default.LoadFromAssemblyPath(platformDllPath);
|
||||
action(library);
|
||||
Console.WriteLineFormatted("Loaded {0} platform emulator from {1} assembly which is using {2} engine.", Color.White, settings);
|
||||
}
|
||||
|
|
@ -39,15 +40,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
Console.WriteLine($"Can't load {platformAssemblyName} assembly.");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
/*Type myClass = (from type in library.GetExportedTypes()
|
||||
where typeof(IMyInterface).IsAssignableFrom(type)
|
||||
select type)
|
||||
.Single();*/
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DIALOGFLOW|AnyCPU'">
|
||||
<Optimize>false</Optimize>
|
||||
<DefineConstants>DEBUG;TRACE;DIALOGFLOW;NETCOREAPP;NETCOREAPP2_1</DefineConstants>
|
||||
<OutputPath></OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ARTICULATE|AnyCPU'">
|
||||
|
|
@ -78,8 +79,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj" />
|
||||
<ProjectReference Include="..\..\botsharp-rasa\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj" />
|
||||
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ namespace BotSharp.WebHost
|
|||
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
||||
});
|
||||
|
||||
PlatformAssembyLoader.LoadPlatformEmulatorAssemblies(Configuration, assembly => mvcBuilder.AddApplicationPart(assembly));
|
||||
|
||||
this.modulesStartup.ConfigureServices(services);
|
||||
//services.AddPlatformEmulator(Configuration, assembly => mvcBuilder.AddApplicationPart(assembly));
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
|
|
|
|||
14
BotSharp.sln
14
BotSharp.sln
|
|
@ -22,8 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Abstracti
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models", "BotSharp.Platform.Models\BotSharp.Platform.Models.csproj", "{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Dialogflow", "..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj", "{83D56CDD-7122-48D3-9CDC-BCE21CB10681}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "..\botsharp-rasa\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj", "{2902810C-F8F2-400E-88DB-72CBE393B175}"
|
||||
EndProject
|
||||
Global
|
||||
|
|
@ -120,18 +118,6 @@ Global
|
|||
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.Build.0 = Release|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.DIALOGFLOW|x64.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.DIALOGFLOW|x64.Build.0 = DIALOGFLOW|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{83D56CDD-7122-48D3-9CDC-BCE21CB10681}.Release|x64.Build.0 = Release|Any CPU
|
||||
{2902810C-F8F2-400E-88DB-72CBE393B175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2902810C-F8F2-400E-88DB-72CBE393B175}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2902810C-F8F2-400E-88DB-72CBE393B175}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
|
|
|||
Loading…
Reference in a new issue