60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using DispenserCore.Model.DTO;
|
|
|
|
namespace DispenserCore.Context;
|
|
|
|
[DispenserCommon.Ioc.Component]
|
|
public class GlobalSessionHolder : INotifyPropertyChanged
|
|
{
|
|
private Session _session;
|
|
|
|
private Session Session
|
|
{
|
|
get => _session;
|
|
set
|
|
{
|
|
_session = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
/// <summary>
|
|
/// 设置用户会话
|
|
/// </summary>
|
|
/// <param name="session"></param>
|
|
public void SetSession(Session session)
|
|
{
|
|
Session = session;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取用户会话信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Session GetSession()
|
|
{
|
|
return Session;
|
|
}
|
|
|
|
public bool Logged()
|
|
{
|
|
return Session != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清理会话会话
|
|
/// </summary>
|
|
public void ClearSession()
|
|
{
|
|
Session = null;
|
|
}
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
} |