zoukankan      html  css  js  c++  java
  • ABP 配置全局数据过滤器 II

    第一篇 那种写法有些复杂,

    简单办法是直接注入

    切换到 ***.EntityFramework 项目

    在Uow 里面创建 ***EfUnitOfWork.cs 类

    public class CooperativeEfUnitOfWork : EfUnitOfWork
        {
            public CooperativeEfUnitOfWork(IIocResolver iocResolver,
                IConnectionStringResolver connectionStringResolver,
                IDbContextResolver dbContextResolver,
                IEfUnitOfWorkFilterExecuter filterExecuter,
                IUnitOfWorkDefaultOptions defaultOptions,
                IDbContextTypeMatcher dbContextTypeMatcher,
                IEfTransactionStrategy transactionStrategy) :
                base(iocResolver, connectionStringResolver, dbContextResolver, filterExecuter, defaultOptions, dbContextTypeMatcher, transactionStrategy)
            {
            }
    
            protected override void BeginUow()
            {
                base.BeginUow();
    
                string major = AbpSession.GetMajor();
                string projectCode = AbpSession.GetProjectCode();
    
                SetFilterParameter(SysConsts.DataFilter.MajorFilter, SysConsts.DataFilter.MajorParameter, major);
                SetFilterParameter(SysConsts.DataFilter.ProjectCodeFilter, SysConsts.DataFilter.ProjectCodeParameter, projectCode);
            }
        }
    

      然后在 **DataModule.cs 里 注册这个类

    using Abp.Dependency;
    using Abp.Domain.Uow;
    using Abp.Modules;
    using Abp.Zero.EntityFramework;
    using JZFZ.Cooperative.EntityFramework;
    using JZFZ.Cooperative.Extensions;
    using JZFZ.Cooperative.Uow;
    using System.Data.Entity;
    using System.Reflection;
    using Abp.Domain.Repositories;
    using JZFZ.Cooperative.Authorization.Users;
    using JZFZ.Cooperative.EntityFramework.Repositories;
    
    namespace JZFZ.Cooperative
    {
        [DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(CooperativeCoreModule))]
        public class CooperativeDataModule : AbpModule
        {
            public override void PreInitialize()
            {
                Database.SetInitializer(new CreateDatabaseIfNotExists<CooperativeDbContext>());
    
                Configuration.DefaultNameOrConnectionString = "Default";
    
                Configuration.UnitOfWork.RegisterFilter(SysConsts.DataFilter.MajorFilter, true);
                Configuration.UnitOfWork.RegisterFilter(SysConsts.DataFilter.ProjectCodeFilter, true);
                Configuration.UnitOfWork.RegisterFilter(SysConsts.DataFilter.ActiveFilter, true);
    
                IocManager.Register<IUnitOfWork, CooperativeEfUnitOfWork>(DependencyLifeStyle.Transient);
                IocManager.Register<IRepository<User, long>, UserRepository>(DependencyLifeStyle.Transient);
            }
    
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            }
        }
    }
    

      

    注意标红的那部分代码

  • 相关阅读:
    python基础之入门
    C#直接删除指定目录下的所有文件及文件夹(保留目录)
    删除Oracle文件、注册表
    WinRAR 激活码(KEY)
    用C#读取txt文件的方法(转)
    c# 生成 xml 文件
    Asp.Net 文件下载1——流下载(适用于大文件且防盗链)(转)
    Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
    响应在此上下文中不可用 asp.net
    Ajax实现局部刷新
  • 原文地址:https://www.cnblogs.com/MindSharing/p/11283914.html
Copyright © 2011-2022 走看看