zoukankan      html  css  js  c++  java
  • Abp用多个DbContext

    using Abp.Domain.Entities;
    using Abp.Domain.Repositories;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace report.EntityFramework.Repositories.Second
    {
        public interface IRepositorySecond<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey> where TEntity : class ,IEntity<TPrimaryKey>
        {
        }
    }
    using Abp.Domain.Entities;
    using Abp.EntityFramework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace report.EntityFramework.Repositories.Second.impl
    {
       public class RepositorySecond<TEntity, TPrimaryKey> : reportSecondRepositoryBase<TEntity, TPrimaryKey>, IRepositorySecond<TEntity, TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
        {
            public RepositorySecond(IDbContextProvider<reportSecondDbContext> dbContextProvider) : base(dbContextProvider)
            {
    
            }
        }
    }
    using Abp.Domain.Entities;
    using Abp.EntityFramework;
    using Abp.EntityFramework.Repositories;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace report.EntityFramework.Repositories
    {
        public abstract class reportSecondRepositoryBase<TEntity, TPrimaryKey> : EfRepositoryBase<reportSecondDbContext, TEntity, TPrimaryKey>
            where TEntity : class, IEntity<TPrimaryKey>
        {
            protected reportSecondRepositoryBase(IDbContextProvider<reportSecondDbContext> dbContextProvider)
                : base(dbContextProvider)
            {
    
            }
    
            //add common methods for all repositories
        }
        public abstract class reportSecondRepositoryBase<TEntity> : reportSecondRepositoryBase<TEntity, int>
        where TEntity : class, IEntity<int>
        {
            protected reportSecondRepositoryBase(IDbContextProvider<reportSecondDbContext> dbContextProvider)
                : base(dbContextProvider)
            {
    
            }
    
            //do not add any method here, add to the class above (since this inherits it)
        }
    }
    using System.Data.Entity;
    using System.Reflection;
    using Abp.Dependency;
    using Abp.Modules;
    using Abp.Zero.EntityFramework;
    using report.EntityFramework;
    using report.EntityFramework.Repositories.Second;
    using report.EntityFramework.Repositories.Second.impl;
    
    namespace report
    {
        [DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(reportCoreModule))]
        public class reportDataModule : AbpModule
        {
            public override void PreInitialize()
            {
                Database.SetInitializer(new CreateDatabaseIfNotExists<reportDbContext>());
    
                Configuration.DefaultNameOrConnectionString = "Default";
            }
    
            public override void Initialize()
            {
                //IocManager.Register(typeof(RepositorySecond<,>), DependencyLifeStyle.Singleton);
                IocManager.Register(typeof(IRepositorySecond<,>),typeof(RepositorySecond <,>));
              
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            }
        }
    }
    作者:银龙

    -------------------------------------------

    个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

    万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

  • 相关阅读:
    Nginx 学习笔记(七)如何解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    jQuery基础 (四)——使用jquery-cookie 实现点赞功能
    Travis CI实现持续部署
    三大云安全工具(CASB、CSPM、CWPP)的使用场景
    数据访问安全代理 CASB
    SDP(软件定义边界)让SDN更安全,你的对面可不能是一条狗!
    从BeyondCorp说起
    [Docker] Docker整体架构图
    当博弈论遇上机器学习:一文读懂相关理论
    用Rust重写Linux内核模块体验
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/15122279.html
Copyright © 2011-2022 走看看