Skip to content

Commit

Permalink
应用层注释
Browse files Browse the repository at this point in the history
  • Loading branch information
boydg123 committed Jul 17, 2017
1 parent 99d4f8d commit 91a7d07
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
40 changes: 31 additions & 9 deletions zero/Derrick.Application/AbpZeroTemplateAppServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,30 @@
namespace Derrick
{
/// <summary>
/// All application services in this application is derived from this class.
/// We can add common application service methods here.
/// All application services in this application is derived from this class.We can add common application service methods here.
/// 应用程序服务基类,可以在此类添加一些公用方法
/// </summary>
public abstract class AbpZeroTemplateAppServiceBase : ApplicationService
{
/// <summary>
/// 商户管理器
/// </summary>
public TenantManager TenantManager { get; set; }

/// <summary>
/// 用户管理器
/// </summary>
public UserManager UserManager { get; set; }

/// <summary>
/// 构造函数
/// </summary>
protected AbpZeroTemplateAppServiceBase()
{
LocalizationSourceName = AbpZeroTemplateConsts.LocalizationSourceName;
}

/// <summary>
/// 获取当前用户 - 异步
/// </summary>
/// <returns></returns>
protected virtual async Task<User> GetCurrentUserAsync()
{
var user = await UserManager.FindByIdAsync(AbpSession.GetUserId());
Expand All @@ -35,7 +45,10 @@ protected virtual async Task<User> GetCurrentUserAsync()

return user;
}

/// <summary>
/// 获取当前用户
/// </summary>
/// <returns></returns>
protected virtual User GetCurrentUser()
{
var user = UserManager.FindById(AbpSession.GetUserId());
Expand All @@ -46,23 +59,32 @@ protected virtual User GetCurrentUser()

return user;
}

/// <summary>
/// 获取当前商户 - 异步
/// </summary>
/// <returns></returns>
protected virtual Task<Tenant> GetCurrentTenantAsync()
{
using (CurrentUnitOfWork.SetTenantId(null))
{
return TenantManager.GetByIdAsync(AbpSession.GetTenantId());
}
}

/// <summary>
/// 获取当前商户
/// </summary>
/// <returns></returns>
protected virtual Tenant GetCurrentTenant()
{
using (CurrentUnitOfWork.SetTenantId(null))
{
return TenantManager.GetById(AbpSession.GetTenantId());
}
}

/// <summary>
/// 检查错误
/// </summary>
/// <param name="identityResult">标识结果</param>
protected virtual void CheckErrors(IdentityResult identityResult)
{
identityResult.CheckErrors(LocalizationManager);
Expand Down
9 changes: 7 additions & 2 deletions zero/Derrick.Application/AbpZeroTemplateApplicationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
namespace Derrick
{
/// <summary>
/// Application layer module of the application.
/// 应用程序中应用层模块
/// </summary>
[DependsOn(typeof(AbpZeroTemplateCoreModule))]
public class AbpZeroTemplateApplicationModule : AbpModule
{
/// <summary>
/// 初始化前
/// </summary>
public override void PreInitialize()
{
//Adding authorization providers
Expand All @@ -23,7 +26,9 @@ public override void PreInitialize()
CustomDtoMapper.CreateMappings(mapper);
});
}

/// <summary>
/// 初始化
/// </summary>
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Expand Down
6 changes: 3 additions & 3 deletions zero/Derrick.Application/AppConsts.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace Derrick
{
/// <summary>
/// Some consts used in the application.
/// 应用程序中使用的常量
/// </summary>
public class AppConsts
{
/// <summary>
/// Default page size for paged requests.
/// 分页请求的默认页码
/// </summary>
public const int DefaultPageSize = 10;

/// <summary>
/// Maximum allowed page size for paged requests.
/// 分页请求的最大允许页码
/// </summary>
public const int MaxPageSize = 1000;
}
Expand Down
19 changes: 17 additions & 2 deletions zero/Derrick.Application/CustomDtoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@

namespace Derrick
{
/// <summary>
/// 自定义Dto映射器
/// </summary>
internal static class CustomDtoMapper
{
/// <summary>
/// 映射前
/// </summary>
private static volatile bool _mappedBefore;
/// <summary>
/// 同步对象
/// </summary>
private static readonly object SyncObj = new object();

/// <summary>
/// 创建映射
/// </summary>
/// <param name="mapper">映射配置表达式</param>
public static void CreateMappings(IMapperConfigurationExpression mapper)
{
lock (SyncObj)
Expand All @@ -23,7 +35,10 @@ public static void CreateMappings(IMapperConfigurationExpression mapper)
_mappedBefore = true;
}
}

/// <summary>
/// 内部创建映射
/// </summary>
/// <param name="mapper">映射配置表达式</param>
private static void CreateMappingsInternal(IMapperConfigurationExpression mapper)
{
mapper.CreateMap<User, UserEditDto>()
Expand Down

0 comments on commit 91a7d07

Please sign in to comment.