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"); } } } } }