添加特性自动依赖注入

This commit is contained in:
陈淳
2022-10-09 17:32:44 +08:00
parent cf37f7c950
commit 0672698ba7
11 changed files with 149 additions and 8 deletions

View File

@@ -0,0 +1,30 @@

using System;
namespace Yi.Framework.Common.Attribute
{
/// <summary>
/// 参考地址https://www.cnblogs.com/kelelipeng/p/10643556.html
/// 1、[AppService]:自动去找接口,如果存在就是接口,如果不存在就是本身
/// 2、[AppService(ServiceType = typeof(注册抽象或者接口或者本身))]手动去注册放type即可
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class AppServiceAttribute : System.Attribute
{
/// <summary>
/// 服务声明周期
/// 不给默认值的话注册的是作用域
/// </summary>
public LifeTime ServiceLifetime { get; set; } = LifeTime.Scoped;
/// <summary>
/// 指定服务类型
/// </summary>
public Type ServiceType { get; set; }
}
public enum LifeTime
{
Transient, Scoped, Singleton
}
}

View File

@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Yi.Framework.Common.Const;
using Yi.Framework.Common.Enum;
namespace Yi.Framework.Common.Attribute
{
[AttributeUsage(AttributeTargets.Method)]
public class LogAttribute : System.Attribute
{
/// <summary>
/// 操作类型
/// </summary>
public OperEnum OperType { get; set; }
/// <summary>
/// 日志标题(模块)
/// </summary>
public string Title { get; set; }
/// <summary>
/// 是否保存请求数据
/// </summary>
public bool IsSaveRequestData { get; set; } = true;
/// <summary>
/// 是否保存返回数据
/// </summary>
public bool IsSaveResponseData { get; set; } = true;
public LogAttribute(string title, OperEnum operationType)
{
this.Title = title;
this.OperType = operationType;
}
}
}