Merge pull request #12857 from abpframework/PlugIn

Add PlugIn test and update its document.
pull/12860/head^2
İsmail ÇAĞDAŞ 3 years ago committed by GitHub
commit 8a835dddaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -178,10 +178,8 @@ namespace MyMvcUIPlugIn
//Add plugin assembly
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(MyMvcUIPlugInModule).Assembly));
//Add views assembly
var viewDllPath = Path.Combine(Path.GetDirectoryName(typeof(MyMvcUIPlugInModule).Assembly.Location), "MyMvcUIPlugIn.Views.dll");
var viewAssembly = new CompiledRazorAssemblyPart(Assembly.LoadFrom(viewDllPath));
mvcBuilder.PartManager.ApplicationParts.Add(viewAssembly);
//Add CompiledRazorAssemblyPart if the PlugIn module contains razor views.
mvcBuilder.PartManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(typeof(MyMvcUIPlugInModule).Assembly));
});
}
}
@ -189,8 +187,7 @@ namespace MyMvcUIPlugIn
````
* Depending on the `AbpAspNetCoreMvcUiThemeSharedModule` since we added the related NuGet package.
* Adding the plug-in's assembly to the `PartManager` of ASP.NET Core MVC. This is required by ASP.NET Core. Otherwise, your controllers inside the plug-in doesn't work.
* Adding the plug-in's views assembly to the `PartManager` of ASP.NET Core MVC. This is required by ASP.NET Core. Otherwise, your views inside the plug-in doesn't work.
* Adding the plug-in's assembly as `AssemblyPart` and `CompiledRazorAssemblyPart` to the `PartManager` of ASP.NET Core MVC. This is required by ASP.NET Core. Otherwise, your controllers or views inside the plug-in doesn't work.
You can now add a razor page, like `MyPlugInPage.cshtml` inside the `Pages` folder:
@ -205,7 +202,7 @@ Now, you can build the plug-in project. It will produce the following output:
![simple-razor-plug-in-dll-file](images/simple-razor-plug-in-dll-file.png)
Copy the `MyMvcUIPlugIn.dll` and `MyMvcUIPlugIn.Views.dll` into the plug-in folder (`D:\Temp\MyPlugIns` for this example).
Copy the `MyMvcUIPlugIn.dll` into the plug-in folder (`D:\Temp\MyPlugIns` for this example).
If you have configured the main application like described above (see Basic Usage section), you should be able to visit the `/MyPlugInPage` URL when your application:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 160 KiB

@ -407,6 +407,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Gdpr.Abstractions"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.RemoteServices", "src\Volo.Abp.RemoteServices\Volo.Abp.RemoteServices.csproj", "{EDFFDA74-090D-439C-A58D-06CCF86D4423}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.PlugIn", "test\Volo.Abp.AspNetCore.Mvc.PlugIn\Volo.Abp.AspNetCore.Mvc.PlugIn.csproj", "{C6D6D878-208A-4FD2-822E-365545D8681B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1213,6 +1215,10 @@ Global
{EDFFDA74-090D-439C-A58D-06CCF86D4423}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDFFDA74-090D-439C-A58D-06CCF86D4423}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDFFDA74-090D-439C-A58D-06CCF86D4423}.Release|Any CPU.Build.0 = Release|Any CPU
{C6D6D878-208A-4FD2-822E-365545D8681B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6D6D878-208A-4FD2-822E-365545D8681B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6D6D878-208A-4FD2-822E-365545D8681B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6D6D878-208A-4FD2-822E-365545D8681B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1418,6 +1424,7 @@ Global
{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{3683340D-92F5-4B14-B77B-34A163333309} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{EDFFDA74-090D-439C-A58D-06CCF86D4423} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{C6D6D878-208A-4FD2-822E-365545D8681B} = {447C8A77-E5F0-4538-8687-7383196D04EA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Mvc.PlugIn;
[DependsOn(typeof(AbpAspNetCoreMvcUiThemeSharedModule))]
public class MyPlungInModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<IMvcBuilder>(mvcBuilder =>
{
//Add plugin assembly
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(MyPlungInModule).Assembly));
//Add CompiledRazorAssemblyPart if the PlugIn module contains razor views.
mvcBuilder.PartManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(typeof(MyPlungInModule).Assembly));
});
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,4 @@
@page
@model Volo.Abp.AspNetCore.Mvc.PlugIn.Volo.Abp.AspNetCore.Mvc.Index
<h1>Welcome to my plug-in page</h1>
<p>This page is located inside a plug-in module! :)</p>

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Volo.Abp.AspNetCore.Mvc.PlugIn.Volo.Abp.AspNetCore.Mvc;
public class Index : PageModel
{
public void OnGet()
{
}
}

@ -0,0 +1,18 @@
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.PlugIn;
public class PlugIn_Tests : AspNetCoreMvcTestBase
{
[Fact]
public async Task Get_PlugIn_Views()
{
var page = await GetResponseAsStringAsync(
"/Index"
);
page.ShouldContain("Welcome to my plug-in page");
}
}

@ -1,8 +1,9 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp.Modularity.PlugIns;
namespace Volo.Abp.AspNetCore.Mvc;
@ -10,7 +11,19 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<AbpAspNetCoreMvcTestModule>();
services.AddApplication<AbpAspNetCoreMvcTestModule>(options =>
{
var hostEnvironment = services.GetHostingEnvironment();
#if DEBUG
var plugDllInPath = Path.Combine(hostEnvironment.ContentRootPath,
@"..\..\..\..\..\Volo.Abp.AspNetCore.Mvc.PlugIn\bin\Debug\net6.0\");
#else
plugDllInPath = Path.Combine(_env.ContentRootPath,
@"..\..\..\..\..\Volo.Abp.AspNetCore.Mvc.PlugIn\bin\Release\net6.0\");
#endif
options.PlugInSources.AddFolder(plugDllInPath);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)

Loading…
Cancel
Save