mirror of https://github.com/abpframework/abp.git
12 changed files with 158 additions and 38 deletions
@ -0,0 +1,37 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Session |
|||
{ |
|||
//TODO: Optimization: Get all settings and cache it!
|
|||
|
|||
public class UserSettingContributor : SettingContributor |
|||
{ |
|||
public const string DefaultEntityType = "User"; |
|||
|
|||
public override string EntityType => DefaultEntityType; |
|||
|
|||
protected ICurrentUser CurrentUser { get; } |
|||
|
|||
public UserSettingContributor(ISettingStore settingStore, ICurrentUser currentUser) |
|||
: base(settingStore) |
|||
{ |
|||
CurrentUser = currentUser; |
|||
} |
|||
|
|||
public override async Task<string> GetOrNullAsync(string name, bool fallback) |
|||
{ |
|||
if (CurrentUser.Id == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return await SettingStore.GetOrNullAsync(name, EntityType, CurrentUser.Id.Value.ToString()); |
|||
} |
|||
|
|||
public override async Task<string> GetOrNullAsync(string name, string entityId, bool fallback = true) |
|||
{ |
|||
return await SettingStore.GetOrNullAsync(name, EntityType, entityId); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Session; |
|||
|
|||
namespace Volo.Abp.Settings |
|||
{ |
|||
public static class UserSettingManagerExtensions |
|||
{ |
|||
public static Task<string> GetOrNullForUserAsync(this ISettingManager settingManager, [NotNull] string name, Guid userId, bool fallback = true) |
|||
{ |
|||
return settingManager.GetOrNullAsync(name, UserSettingContributor.DefaultEntityType, userId.ToString(), fallback); |
|||
} |
|||
|
|||
public static Task<List<SettingValue>> GetAllForUserAsync(this ISettingManager settingManager, Guid userId, bool fallback = true) |
|||
{ |
|||
return settingManager.GetAllAsync(UserSettingContributor.DefaultEntityType, userId.ToString(), fallback); |
|||
} |
|||
|
|||
public static Task SetForUserAsync(this ISettingManager settingManager, Guid userId, [NotNull] string name, [CanBeNull] string value) |
|||
{ |
|||
return settingManager.SetAsync(name, value, UserSettingContributor.DefaultEntityType, userId.ToString()); |
|||
} |
|||
} |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Settings |
|||
{ |
|||
public class DefaultSettingContributor : ISettingContributor, ISingletonDependency |
|||
{ |
|||
private readonly ISettingStore _settingStore; |
|||
|
|||
public DefaultSettingContributor(ISettingStore settingStore) |
|||
{ |
|||
_settingStore = settingStore; |
|||
} |
|||
|
|||
public async Task<string> GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true) |
|||
{ |
|||
//TODO: Optimization: Get all settings and cache it!
|
|||
return await _settingStore.GetOrNullAsync(name, null, null); |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +1,10 @@ |
|||
namespace Volo.Abp.Settings |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Settings |
|||
{ |
|||
public interface ISettingDefinitionManager |
|||
{ |
|||
SettingDefinition Get(string name); |
|||
[NotNull] |
|||
SettingDefinition Get([NotNull] string name); |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Settings |
|||
{ |
|||
public abstract class SettingContributor : ISettingContributor, ISingletonDependency |
|||
{ |
|||
public abstract string EntityType { get; } |
|||
|
|||
protected ISettingStore SettingStore { get; } |
|||
|
|||
protected SettingContributor(ISettingStore settingStore) |
|||
{ |
|||
SettingStore = settingStore; |
|||
} |
|||
|
|||
public abstract Task<string> GetOrNullAsync(string name, bool fallback); |
|||
|
|||
public abstract Task<string> GetOrNullAsync(string name, string entityId, bool fallback = true); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue