Files
IM_NEW/IM.ASPNETCore/UnitOfWorkAttribute.cs
T
2026-05-09 17:06:30 +08:00

25 lines
718 B
C#

using Microsoft.EntityFrameworkCore;
namespace IM.ASPNETCore
{
[AttributeUsage(AttributeTargets.Class
| AttributeTargets.Method, AllowMultiple = false, Inherited = true
)]
public class UnitOfWorkAttribute : Attribute
{
public Type[] DbContextTypes { get; private set; }
public UnitOfWorkAttribute(params Type[] dbContextTypes)
{
this.DbContextTypes = dbContextTypes;
foreach (var type in dbContextTypes)
{
if (!typeof(DbContext).IsAssignableFrom(type))
{
throw new ArgumentException($"{type} must inherit from DbContext");
}
}
}
}
}