From 0f70f641346d9db18557d00fd19bed9dc3d57c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 3 Nov 2017 15:18:01 +0300 Subject: [PATCH] Created ServiceBasedPageModelActivatorProvider. --- .../Pages/App/Tickets/Index.cshtml.cs | 1 - .../AbpDesk.Web.Mvc/Pages/Index.cshtml.cs | 4 ++-- .../Volo.Abp.AspNetCore.Mvc.csproj | 4 ++++ .../AspNetCore/Mvc/RazorPages/AbpPageModel.cs | 3 ++- .../ServiceBasedPageModelActivatorProvider.cs | 23 +++++++++++++++++++ .../Pages/Identity/Users/Index.cshtml.cs | 4 ++-- 6 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml.cs index 00ee5c14d9..3953df33fc 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml.cs @@ -19,7 +19,6 @@ namespace AbpDesk.Web.Mvc.Pages.App.Tickets public async Task OnGetAsync(GetAllTicketsInput input) { - var uow = CurrentUnitOfWork; var result = await _ticketAppService.GetAll(input); Tickets = result.Items; } diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/Index.cshtml.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Pages/Index.cshtml.cs index c289ecbc88..8068ab311c 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/Index.cshtml.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/Pages/Index.cshtml.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; +using Volo.Abp.AspNetCore.Mvc.RazorPages; namespace AbpDesk.Web.Mvc.Pages { - public class IndexModel : PageModel + public class IndexModel : AbpPageModel { public void OnGet() { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj b/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj index 0eada12839..9de9226814 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj @@ -23,4 +23,8 @@ + + + + diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs index eec6fcf081..dd27354cd1 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs @@ -2,13 +2,14 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; namespace Volo.Abp.AspNetCore.Mvc.RazorPages { - public abstract class AbpPageModel : PageModel + public abstract class AbpPageModel : PageModel, ITransientDependency //TODO: Register PageModels by convention, instead of using ITransientDependency { public IUnitOfWorkManager UnitOfWorkManager { get; set; } diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs new file mode 100644 index 0000000000..89e0bd12ff --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs @@ -0,0 +1,23 @@ +using System; +using JetBrains.Annotations; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.RazorPages +{ + [Dependency(ReplaceServices = true)] + public class ServiceBasedPageModelActivatorProvider : IPageModelActivatorProvider, ITransientDependency + { + public Func CreateActivator([NotNull] CompiledPageActionDescriptor descriptor) + { + Check.NotNull(descriptor, nameof(descriptor)); + return context => context.HttpContext.RequestServices.GetRequiredService(descriptor.ModelTypeInfo); + } + + public Action CreateReleaser([NotNull] CompiledPageActionDescriptor descriptor) + { + return null; + } + } +} diff --git a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/Index.cshtml.cs b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/Index.cshtml.cs index 1557445d6b..4997f911f7 100644 --- a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/Index.cshtml.cs +++ b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/Index.cshtml.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; +using Volo.Abp.AspNetCore.Mvc.RazorPages; namespace Volo.Abp.Identity.Web.Pages.Identity.Users { - public class IndexModel : PageModel + public class IndexModel : AbpPageModel { public void OnGet() {