Skip to content

Lu Ban Of .Net - .NET 工匠辅助库。Net 高可用、高效率的扩展库,希望对 .NET 开发者及爱好者带来便捷,告别996,远离ICU!!!

License

Notifications You must be signed in to change notification settings

CacoCode-zz/LBON

Repository files navigation

Github Build Status nuget downloads License

中文| English

Lu Ban Of .Net - .NET 鲁班工匠辅助库

.Net 高可用、高效率的扩展库,希望对 .NET 开发者及爱好者带来便捷,告别996,远离ICU!!!

Nuget

名称 Nuget
LBON.Consts NuGet
LBON.Extensions NuGet
LBON.Helper NuGet
LBON.DependencyInjection NuGet
LBON.EntityFrameworkCore NuGet

功能模块

LBON.EntityFrameworkCore

EntityFramework 底层实现和扩展类,包括创建审计字段、修改审计字段、删除审计字段和扩展字段的封装

    public class FullAuditedEntity<TKey,TUser>:EntityBase<TKey>, ICreationAudited<TUser>, IModificationAudited<TUser>, IDeletionAudited<TUser>
    {
        public TUser CreatorId { get; set; }
        public DateTime CreationTime { get; set; }
        public TUser LastModifierId { get; set; }
        public DateTime? LastModificationTime { get; set; }
        public TUser DeleterId { get; set; }
        public bool IsDeleted { get; set; }
        public DateTime? DeletionTime { get; set; }
    }

另外还添加ExtendableObjectExtensions扩展类去设置(SetData)、获取(GetData) ExtendableObject字段的值。封装IEfRepository,满足绝大部分EF操作

        IQueryable<TEntity> GetAll(params Expression<Func<TEntity, object>>[] propertySelectors);

        IQueryable<TEntity> GetAll(Expression<Func<TEntity, bool>> expression,
            params Expression<Func<TEntity, object>>[] propertySelectors);

        TEntity Find(TPrimaryKey id);

        Task<TEntity> FindAsync(TPrimaryKey id);

        TEntity Get(Expression<Func<TEntity, bool>> expression,
            params Expression<Func<TEntity, object>>[] propertySelectors);

        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> expression,
            params Expression<Func<TEntity, object>>[] propertySelectors);

        void Insert(TEntity entity, bool autoSave = true);

        Task InsertAsync(TEntity entity, bool autoSave = true);

        Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity, bool autoSave = true);

        void InsertList(List<TEntity> entities, bool autoSave = true);

        Task InsertListAsync(List<TEntity> entities, bool autoSave = true);

        void Update(TEntity entity, bool autoSave = true);

        Task UpdateAsync(TEntity entity, bool autoSave = true);

        void UpdateList(IEnumerable<TEntity> entities);

        Task UpdateListAsync(IEnumerable<TEntity> entities);

        void Delete(TPrimaryKey id, bool autoSave = true);

        Task DeleteAsync(TPrimaryKey id, bool autoSave = true);

        void Delete(TEntity entity, bool autoSave = true);

        Task DeleteAsync(TEntity entity, bool autoSave = true);

        void HardDelete(TPrimaryKey id, bool autoSave = true);

        Task HardDeleteAsync(TPrimaryKey id, bool autoSave = true);

        void HardDelete(TEntity entity, bool autoSave = true);

        Task HardDeleteAsync(TEntity entity, bool autoSave = true);

在.NET CORE 中使用的话,可以引入LBON.EntityFrameworkCore库,里面封装了对IEfRepository的以来注入,并且实现了对IScopedDependency、ISingletonDependency、ITransientDependency继承类的自动批量注入,方便使用者注入自身服务。

public void ConfigureServices(IServiceCollection services)
{
    services.ServiceRegister(Assembly.Load("AssemblyName"), Assembly.Load("AssemblyName"));
}
// Scoped
public interface IProductService: IScopedDependency
{
}
// Singleton
public interface IProductService: ISingletonDependency
{
}
// Transient
public interface IProductService: ITransientDependency
{
}

LBON.Extensions

LBON.Helper

LBON.Consts

About

Lu Ban Of .Net - .NET 工匠辅助库。Net 高可用、高效率的扩展库,希望对 .NET 开发者及爱好者带来便捷,告别996,远离ICU!!!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages