Browse Source

Introduce AbpControllerBase to create API Controllers

pull/10198/head
liangshiwei 4 years ago
parent
commit
e90baa2301
  1. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/AbpTenantController.cs
  2. 105
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerBase.cs
  3. 2
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs
  4. 2
      modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs
  5. 2
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs
  6. 2
      modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs
  7. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/BlogFilesController.cs
  8. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/BlogsController.cs
  9. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/CommentsController.cs
  10. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs
  11. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/CmsKitAdminController.cs
  13. 2
      modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/CmsKitControllerBase.cs
  14. 2
      modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs
  15. 2
      modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs
  16. 2
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs
  17. 2
      modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs
  18. 2
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs
  19. 2
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs
  20. 2
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs
  21. 2
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs
  22. 2
      modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/PermissionsController.cs
  23. 2
      modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi/Volo/Abp/SettingManagement/EmailSettingsController.cs
  24. 2
      modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi/Volo/Abp/TenantManagement/TenantController.cs
  25. 2
      templates/module/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi/MyProjectNameController.cs

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/AbpTenantController.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
@ -10,7 +11,7 @@ namespace Pages.Abp.MultiTenancy
[Area("abp")]
[RemoteService(Name = "abp")]
[Route("api/abp/multi-tenancy")]
public class AbpTenantController : AbpController, IAbpTenantAppService
public class AbpTenantController : AbpControllerBase, IAbpTenantAppService
{
private readonly IAbpTenantAppService _abpTenantAppService;

105
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerBase.cs

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Mvc.Validation;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.Guids;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Timing;
using Volo.Abp.Uow;
using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Mvc
{
public abstract class AbpControllerBase : ControllerBase, IAvoidDuplicateCrossCuttingConcerns
{
public IAbpLazyServiceProvider LazyServiceProvider { get; set; }
protected IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>();
protected Type ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService<IObjectMapper>(provider =>
ObjectMapperContext == null
? provider.GetRequiredService<IObjectMapper>()
: (IObjectMapper) provider.GetRequiredService(typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext)));
protected IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetService<IGuidGenerator>(SimpleGuidGenerator.Instance);
protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>();
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance);
protected ICurrentUser CurrentUser => LazyServiceProvider.LazyGetRequiredService<ICurrentUser>();
protected ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
protected IAuthorizationService AuthorizationService => LazyServiceProvider.LazyGetRequiredService<IAuthorizationService>();
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;
protected IClock Clock => LazyServiceProvider.LazyGetRequiredService<IClock>();
protected IModelStateValidator ModelValidator => LazyServiceProvider.LazyGetRequiredService<IModelStateValidator>();
protected IFeatureChecker FeatureChecker => LazyServiceProvider.LazyGetRequiredService<IFeatureChecker>();
protected IStringLocalizerFactory StringLocalizerFactory => LazyServiceProvider.LazyGetRequiredService<IStringLocalizerFactory>();
protected IStringLocalizer L
{
get
{
if (_localizer == null)
{
_localizer = CreateLocalizer();
}
return _localizer;
}
}
private IStringLocalizer _localizer;
protected Type LocalizationResource
{
get => _localizationResource;
set
{
_localizationResource = value;
_localizer = null;
}
}
private Type _localizationResource = typeof(DefaultResource);
public List<string> AppliedCrossCuttingConcerns { get; } = new List<string>();
protected virtual IStringLocalizer CreateLocalizer()
{
if (LocalizationResource != null)
{
return StringLocalizerFactory.Create(LocalizationResource);
}
var localizer = StringLocalizerFactory.CreateDefaultOrNull();
if (localizer == null)
{
throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!");
}
return localizer;
}
protected virtual void ValidateModel()
{
ModelValidator?.Validate(ModelState);
}
}
}

2
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
[Area("abp")]
[RemoteService(Name = "abp")]
[Route("api/abp/application-configuration")]
public class AbpApplicationConfigurationController : AbpController, IAbpApplicationConfigurationAppService
public class AbpApplicationConfigurationController : AbpControllerBase, IAbpApplicationConfigurationAppService
{
private readonly IAbpApplicationConfigurationAppService _applicationConfigurationAppService;
private readonly IAbpAntiForgeryManager _antiForgeryManager;

2
modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.Account
[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)]
[Area("account")]
[Route("api/account")]
public class AccountController : AbpController, IAccountAppService
public class AccountController : AbpControllerBase, IAccountAppService
{
protected IAccountAppService AccountAppService { get; }

2
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs

@ -22,7 +22,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
[ControllerName("Login")]
[Area("account")]
[Route("api/account")]
public class AccountController : AbpController
public class AccountController : AbpControllerBase
{
protected SignInManager<IdentityUser> SignInManager { get; }
protected IdentityUserManager UserManager { get; }

2
modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs

@ -13,7 +13,7 @@ namespace Volo.Blogging.Admin
[RemoteService(Name = BloggingAdminRemoteServiceConsts.RemoteServiceName)]
[Area("bloggingAdmin")]
[Route("api/blogging/blogs/admin")]
public class BlogManagementController : AbpController, IBlogManagementAppService
public class BlogManagementController : AbpControllerBase, IBlogManagementAppService
{
private readonly IBlogManagementAppService _blogManagementAppService;

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/BlogFilesController.cs

@ -10,7 +10,7 @@ namespace Volo.Blogging
[RemoteService(Name = BloggingRemoteServiceConsts.RemoteServiceName)]
[Area("blogging")]
[Route("api/blogging/files")]
public class BlogFilesController : AbpController, IFileAppService
public class BlogFilesController : AbpControllerBase, IFileAppService
{
private readonly IFileAppService _fileAppService;

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/BlogsController.cs

@ -12,7 +12,7 @@ namespace Volo.Blogging
[RemoteService(Name = BloggingRemoteServiceConsts.RemoteServiceName)]
[Area("blogging")]
[Route("api/blogging/blogs")]
public class BlogsController : AbpController, IBlogAppService
public class BlogsController : AbpControllerBase, IBlogAppService
{
private readonly IBlogAppService _blogAppService;

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/CommentsController.cs

@ -12,7 +12,7 @@ namespace Volo.Blogging
[RemoteService(Name = BloggingRemoteServiceConsts.RemoteServiceName)]
[Area("blogging")]
[Route("api/blogging/comments")]
public class CommentsController : AbpController, ICommentAppService
public class CommentsController : AbpControllerBase, ICommentAppService
{
private readonly ICommentAppService _commentAppService;

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs

@ -11,7 +11,7 @@ namespace Volo.Blogging
[RemoteService(Name = BloggingRemoteServiceConsts.RemoteServiceName)]
[Area("blogging")]
[Route("api/blogging/posts")]
public class PostsController : AbpController, IPostAppService
public class PostsController : AbpControllerBase, IPostAppService
{
private readonly IPostAppService _postAppService;

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/TagsController.cs

@ -12,7 +12,7 @@ namespace Volo.Blogging
[RemoteService(Name = BloggingRemoteServiceConsts.RemoteServiceName)]
[Area("blogging")]
[Route("api/blogging/tags")]
public class TagsController : AbpController, ITagAppService
public class TagsController : AbpControllerBase, ITagAppService
{
private readonly ITagAppService _tagAppService;

2
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/CmsKitAdminController.cs

@ -3,7 +3,7 @@ using Volo.CmsKit.Localization;
namespace Volo.CmsKit.Admin
{
public abstract class CmsKitAdminController : AbpController
public abstract class CmsKitAdminController : AbpControllerBase
{
protected CmsKitAdminController()
{

2
modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/CmsKitControllerBase.cs

@ -3,7 +3,7 @@ using Volo.CmsKit.Localization;
namespace Volo.CmsKit
{
public abstract class CmsKitControllerBase : AbpController
public abstract class CmsKitControllerBase : AbpControllerBase
{
protected CmsKitControllerBase()
{

2
modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs

@ -13,7 +13,7 @@ namespace Volo.Docs.Admin
[Area("docs-admin")]
[ControllerName("DocumentsAdmin")]
[Route("api/docs/admin/documents")]
public class DocumentsAdminController : AbpController, IDocumentAdminAppService
public class DocumentsAdminController : AbpControllerBase, IDocumentAdminAppService
{
private readonly IDocumentAdminAppService _documentAdminAppService;

2
modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs

@ -12,7 +12,7 @@ namespace Volo.Docs.Admin
[Area("docs-admin")]
[ControllerName("ProjectsAdmin")]
[Route("api/docs/admin/projects")]
public class ProjectsAdminController : AbpController, IProjectAdminAppService
public class ProjectsAdminController : AbpControllerBase, IProjectAdminAppService
{
private readonly IProjectAdminAppService _projectAppService;

2
modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs

@ -11,7 +11,7 @@ namespace Volo.Docs.Projects
[Area("docs")]
[ControllerName("Project")]
[Route("api/docs/projects")]
public class DocsProjectController : AbpController, IProjectAppService
public class DocsProjectController : AbpControllerBase, IProjectAppService
{
protected IProjectAppService ProjectAppService { get; }

2
modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.FeatureManagement
[RemoteService(Name = FeatureManagementRemoteServiceConsts.RemoteServiceName)]
[Area("featureManagement")]
[Route("api/feature-management/features")]
public class FeaturesController : AbpController, IFeatureAppService
public class FeaturesController : AbpControllerBase, IFeatureAppService
{
protected IFeatureAppService FeatureAppService { get; }

2
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.Identity
[Area("identity")]
[ControllerName("Role")]
[Route("api/identity/roles")]
public class IdentityRoleController : AbpController, IIdentityRoleAppService
public class IdentityRoleController : AbpControllerBase, IIdentityRoleAppService
{
protected IIdentityRoleAppService RoleAppService { get; }

2
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.Identity
[Area("identity")]
[ControllerName("User")]
[Route("api/identity/users")]
public class IdentityUserController : AbpController, IIdentityUserAppService
public class IdentityUserController : AbpControllerBase, IIdentityUserAppService
{
protected IIdentityUserAppService UserAppService { get; }

2
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs

@ -11,7 +11,7 @@ namespace Volo.Abp.Identity
[Area("identity")]
[ControllerName("UserLookup")]
[Route("api/identity/users/lookup")]
public class IdentityUserLookupController : AbpController, IIdentityUserLookupAppService
public class IdentityUserLookupController : AbpControllerBase, IIdentityUserLookupAppService
{
protected IIdentityUserLookupAppService LookupAppService { get; }

2
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.Identity
[Area("identity")]
[ControllerName("Profile")]
[Route("/api/identity/my-profile")]
public class ProfileController : AbpController, IProfileAppService
public class ProfileController : AbpControllerBase, IProfileAppService
{
protected IProfileAppService ProfileAppService { get; }

2
modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/PermissionsController.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.PermissionManagement
[RemoteService(Name = PermissionManagementRemoteServiceConsts.RemoteServiceName)]
[Area("permissionManagement")]
[Route("api/permission-management/permissions")]
public class PermissionsController : AbpController, IPermissionAppService
public class PermissionsController : AbpControllerBase, IPermissionAppService
{
protected IPermissionAppService PermissionAppService { get; }

2
modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi/Volo/Abp/SettingManagement/EmailSettingsController.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.SettingManagement
[RemoteService(Name = SettingManagementRemoteServiceConsts.RemoteServiceName)]
[Area("settingManagement")]
[Route("api/setting-management/emailing")]
public class EmailSettingsController : AbpController, IEmailSettingsAppService
public class EmailSettingsController : AbpControllerBase, IEmailSettingsAppService
{
private readonly IEmailSettingsAppService _emailSettingsAppService;

2
modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi/Volo/Abp/TenantManagement/TenantController.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.TenantManagement
[RemoteService(Name = TenantManagementRemoteServiceConsts.RemoteServiceName)]
[Area("multi-tenancy")]
[Route("api/multi-tenancy/tenants")]
public class TenantController : AbpController, ITenantAppService //TODO: Throws exception on validation if we inherit from Controller
public class TenantController : AbpControllerBase, ITenantAppService //TODO: Throws exception on validation if we inherit from Controller
{
protected ITenantAppService TenantAppService { get; }

2
templates/module/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi/MyProjectNameController.cs

@ -3,7 +3,7 @@ using Volo.Abp.AspNetCore.Mvc;
namespace MyCompanyName.MyProjectName
{
public abstract class MyProjectNameController : AbpController
public abstract class MyProjectNameController : AbpControllerBase
{
protected MyProjectNameController()
{

Loading…
Cancel
Save