Skip to content

Commit 9f3be16

Browse files
author
Lamond Lu
committed
merge the code from 'dynamic load branch' to 'master'
2 parents 65e9530 + 9919d7a commit 9f3be16

35 files changed

+4501
-68
lines changed

DemoPlugin1/DemoPlugin1.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<OutputType>Library</OutputType>
56
</PropertyGroup>
67

78
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
89
<OutputPath></OutputPath>
910
</PropertyGroup>
1011

11-
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="3.0.0" />
13-
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
14-
</ItemGroup>
15-
1612
<ItemGroup>
1713
<ProjectReference Include="..\DemoReferenceLibrary\DemoReferenceLibrary.csproj" />
1814
<ProjectReference Include="..\Mystique.Core\Mystique.Core.csproj" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using DemoReferenceLibrary;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace DemoPlugin2.Controllers
5+
{
6+
[Area("DemoPlugin2")]
7+
public class Plugin1Controller : Controller
8+
{
9+
public IActionResult HelloWorld()
10+
{
11+
var content = new Demo().SayHello();
12+
ViewBag.Content = content;
13+
return View();
14+
}
15+
}
16+
}

DemoPlugin2/DemoPlugin2.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<OutputType>Library</OutputType>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
<OutputPath></OutputPath>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\DemoReferenceLibrary\DemoReferenceLibrary.csproj" />
14+
<ProjectReference Include="..\Mystique.Core\Mystique.Core.csproj" />
15+
</ItemGroup>
16+
17+
18+
<ItemGroup>
19+
<None Update="Views\**">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Mystique.Core.Contracts;
2+
using Mystique.Core.DomainModel;
3+
using Mystique.Core.Helpers;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
namespace DemoPlugin2.Migrations
9+
{
10+
public class Migration_1_0_0 : BaseMigration
11+
{
12+
private static Mystique.Core.DomainModel.Version _version = new Mystique.Core.DomainModel.Version("1.0.0");
13+
private static string _upScripts = @"CREATE TABLE [dbo].[Test3](
14+
TestId[uniqueidentifier] NOT NULL,
15+
);";
16+
private static string _downScripts = @"DROP TABLE [dbo].[Test3]";
17+
18+
public Migration_1_0_0(DbHelper dbHelper) : base(dbHelper, _version)
19+
{
20+
21+
}
22+
23+
public override void MigrationDown(Guid pluginId)
24+
{
25+
SQL(_downScripts);
26+
27+
base.RemoveMigrationScripts(pluginId);
28+
}
29+
30+
public override void MigrationUp(Guid pluginId)
31+
{
32+
SQL(_upScripts);
33+
34+
base.WriteMigrationScripts(pluginId, _upScripts, _downScripts);
35+
}
36+
}
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@{
2+
3+
}
4+
5+
<h1>@ViewBag.Content</h1>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "~/Views/Shared/_Layout.cshtml";
3+
}

DemoReferenceLibrary/Demo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Demo
88
{
99
public string SayHello()
1010
{
11-
return "Hello World. Version 1";
11+
return "Hello World. Version 2";
1212
}
1313
}
1414
}

DemoReferenceLibrary/DemoReferenceLibrary.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
6+
<FileVersion>1.0.1.0</FileVersion>
57
</PropertyGroup>
68

79
</Project>

Mystique.Core.Mvc/Infrastructure/MystiqueStartup.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@ public static void MystiqueSetup(this IServiceCollection services, IConfiguratio
2929
services.AddScoped<IPluginManager, PluginManager>();
3030
services.AddScoped<IUnitOfWork, UnitOfWork>();
3131
services.AddSingleton<IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
32+
services.AddSingleton<IReferenceContainer, DefaultReferenceContainer>();
33+
services.AddSingleton<IReferenceLoader, DefaultReferenceLoader>();
34+
services.AddSingleton<IDependanceLoader, DefaultDependanceLoader>();
3235
services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);
3336

34-
var mvcBuilder = services.AddMvc().AddRazorRuntimeCompilation(o =>
35-
{
36-
foreach (var item in _presets)
37-
{
38-
o.AdditionalReferencePaths.Add(item);
39-
}
40-
41-
AdditionalReferencePathHolder.AdditionalReferencePaths = o.AdditionalReferencePaths;
42-
});
37+
var mvcBuilder = services.AddMvc();
4338

4439
var provider = services.BuildServiceProvider();
4540
using (var scope = provider.CreateScope())
@@ -48,21 +43,21 @@ public static void MystiqueSetup(this IServiceCollection services, IConfiguratio
4843

4944
var unitOfWork = scope.ServiceProvider.GetService<IUnitOfWork>();
5045
var allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
46+
var loader = scope.ServiceProvider.GetService<IReferenceLoader>();
5147

5248
foreach (var plugin in allEnabledPlugins)
5349
{
5450
var context = new CollectibleAssemblyLoadContext();
5551
var moduleName = plugin.Name;
5652
var filePath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll";
53+
var jsonPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.deps.json";
5754
var referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}";
5855

5956
_presets.Add(filePath);
6057
using (var fs = new FileStream(filePath, FileMode.Open))
6158
{
6259
var assembly = context.LoadFromStream(fs);
63-
64-
DefaultReferenceLoader loader = new DefaultReferenceLoader(referenceFolderPath, $"{moduleName}.dll");
65-
loader.LoadStreamsIntoContext(context);
60+
loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly, jsonPath);
6661

6762
var controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
6863
mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
@@ -71,6 +66,16 @@ public static void MystiqueSetup(this IServiceCollection services, IConfiguratio
7166
}
7267
}
7368

69+
mvcBuilder.AddRazorRuntimeCompilation(o =>
70+
{
71+
foreach (var item in _presets)
72+
{
73+
o.AdditionalReferencePaths.Add(item);
74+
}
75+
76+
AdditionalReferencePathHolder.AdditionalReferencePaths = o.AdditionalReferencePaths;
77+
});
78+
7479
services.Configure<RazorViewEngineOptions>(o =>
7580
{
7681
o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);

Mystique.Core.Mvc/MvcModuleSetup.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ namespace Mystique.Core.Mvc
1414
public class MvcModuleSetup : IMvcModuleSetup
1515
{
1616
private ApplicationPartManager _partManager;
17+
private IReferenceLoader _referenceLoader = null;
1718

18-
public MvcModuleSetup(ApplicationPartManager partManager)
19+
public MvcModuleSetup(ApplicationPartManager partManager, IReferenceLoader referenceLoader)
1920
{
2021
_partManager = partManager;
22+
_referenceLoader = referenceLoader;
2123
}
2224

2325
public void EnableModule(string moduleName)
@@ -27,15 +29,12 @@ public void EnableModule(string moduleName)
2729
var context = new CollectibleAssemblyLoadContext();
2830

2931
var filePath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll";
32+
var jsonPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.deps.json";
3033
var referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}";
3134
using (var fs = new FileStream(filePath, FileMode.Open))
3235
{
3336
var assembly = context.LoadFromStream(fs);
34-
35-
36-
DefaultReferenceLoader loader = new DefaultReferenceLoader(referenceFolderPath, $"{moduleName}.dll");
37-
loader.LoadStreamsIntoContext(context);
38-
37+
_referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, assembly, jsonPath);
3938

4039
var controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
4140

0 commit comments

Comments
 (0)