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

      

    注意标红的那部分代码

  • 相关阅读:
    virtual方法和abstract方法的使用(轉載)
    C# 如何寫入cookie
    Literal的一般用法,与Label对比 MSDN上的解释
    With temp as---sql语句用法 转
    GridView __DataKey 使用
    .net里radiobutton 两个怎么才能让他只选择一个
    Server.Transfer()与Response.Redirect()区别
    OnInit 事件
    ajax中Sys.WebForms.PageRequestManager的事件激发顺序
    Linux CentOS 查看某个进程打开的文件(文件描述符)
  • 原文地址:https://www.cnblogs.com/MindSharing/p/11283914.html
Copyright © 2011-2022 走看看