diff --git a/docs/en/PlugIn-Modules.md b/docs/en/PlugIn-Modules.md index 1d613582ab..5c0cdacfd3 100644 --- a/docs/en/PlugIn-Modules.md +++ b/docs/en/PlugIn-Modules.md @@ -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: diff --git a/docs/en/images/simple-razor-plug-in-dll-file.png b/docs/en/images/simple-razor-plug-in-dll-file.png index 06b7a565fe..9561941952 100644 Binary files a/docs/en/images/simple-razor-plug-in-dll-file.png and b/docs/en/images/simple-razor-plug-in-dll-file.png differ diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index f92a9d336b..fadd40bcc5 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -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} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/MyPlungInModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/MyPlungInModule.cs new file mode 100644 index 0000000000..5f007720b3 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/MyPlungInModule.cs @@ -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(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)); + }); + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo.Abp.AspNetCore.Mvc.PlugIn.csproj b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo.Abp.AspNetCore.Mvc.PlugIn.csproj new file mode 100644 index 0000000000..91ca2b1312 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo.Abp.AspNetCore.Mvc.PlugIn.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + Library + true + + + + + + + diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml new file mode 100644 index 0000000000..6ed75571d1 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml @@ -0,0 +1,4 @@ +@page +@model Volo.Abp.AspNetCore.Mvc.PlugIn.Volo.Abp.AspNetCore.Mvc.Index +

Welcome to my plug-in page

+

This page is located inside a plug-in module! :)

diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml.cs new file mode 100644 index 0000000000..2570e93950 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.PlugIn/Volo/Abp/AspNetCore/Mvc/Index.cshtml.cs @@ -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() + { + + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PlugIn/PlugIn_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PlugIn/PlugIn_Tests.cs new file mode 100644 index 0000000000..c8519e9612 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PlugIn/PlugIn_Tests.cs @@ -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"); + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs index f913b431e7..e26e6ce2c3 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs @@ -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(); + services.AddApplication(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)