Admin.Core/src/platform/ZhonTai.Admin/Services/Base/BaseService.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MapsterMapper;
using ZhonTai.Admin.Core.Auth;
using ZhonTai.Admin.Tools.Cache;
using ZhonTai.Common.Extensions;
using Microsoft.AspNetCore.Mvc;
namespace ZhonTai.Admin.Services;
public abstract class BaseService: IBaseService
{
protected readonly object ServiceProviderLock = new object();
protected IDictionary<Type, object> CachedServices = new Dictionary<Type, object>();
private ICacheTool _cache;
private ILoggerFactory _loggerFactory;
private IMapper _mapper;
private IUser _user;
/// <summary>
/// 缓存
/// </summary>
public ICacheTool Cache => LazyGetRequiredService(ref _cache);
/// <summary>
/// 日志工厂
/// </summary>
public ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory);
/// <summary>
/// 映射
/// </summary>
public IMapper Mapper => LazyGetRequiredService(ref _mapper);
public IServiceProvider ServiceProvider { get; set; }
/// <summary>
/// 用户信息
/// </summary>
public IUser User => LazyGetRequiredService(ref _user);
/// <summary>
/// 日志
/// </summary>
protected ILogger Logger => _lazyLogger.Value;
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true);
protected TService LazyGetRequiredService<TService>(ref TService reference)
{
if (reference == null)
{
lock (ServiceProviderLock)
{
if (reference == null)
{
reference = ServiceProvider.GetRequiredService<TService>();
后面还有 29 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
