Abp添加新的接口(扩展底层接口)

https://aspnetboilerplate.com/Templates 创建项目之后,下载用Vs2019打开(vs2017不支持netcore3.0)结构如下:

一、

 

2、

在xx.core中新增实体类Code  codemapping 

 

 

 

 3、

 在xx.core 中新增 仓储接口

4、在xx.EntityFrameWork中实现仓储

 

不要忘记在项目中上下文中做如下设置,否则执行add-migration 及update-database 时不会产生对应的表结构 

 

 

 

 

 public class CodeMappingRepository:WuMingRepositoryBase<CodeMapping,int>,ICodeMappingRepository
    {
        public CodeMappingRepository(IDbContextProvider<WuMingDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public int Account()
        {
            throw new NotImplementedException();
        }
    }
public class CodeRepository :WuMingRepositoryBase<Code,int>,ICodeRepository
    {
        public CodeRepository(IDbContextProvider<WuMingDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
    }

 

5 .在xx.Application 定义Ixxservice 和实现实现接口

定义和实现:

 

ICodeAppService
public interface ICodeAppService: IApplicationService
    {
        List<Code> GetCodes();

        void UpdateCode(Code entity);

        void CreateCode(Code entity);

        void DeleteCode(int Id);
    }

CodeAppService:

  [AbpAllowAnonymous]
    public class CodeAppService :WuMingAppServiceBase, ICodeAppService
    {

        ICodeRepository _CodeRepository;
        ICodeMappingRepository _CodeMappingRepository;


        public CodeAppService(ICodeRepository CodeRepository, ICodeMappingRepository CodeMappingRepository) 
        {
            _CodeRepository = CodeRepository;
            _CodeMappingRepository = CodeMappingRepository;
        }

        public void CreateCode(Code entity)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                _CodeRepository.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }

        public void DeleteCode(int Id)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
               // _CodeRepository.Delete(new Code() { Id = Id });

            }
            catch (Exception ex)
            {

                Logger.Error(ex.ToString());
            }

        }

        public List<Code> GetCodes()
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                //return _CodeRepository.GetAll().ToList();
                return null;
            }
            catch (Exception ex)
            {

                throw;
            }
        }

        public void UpdateCode(Code entity)
        {
            Logger.Info($"Created a User for entity at:{DateTime.Now}");
            try
            {
                // _CodeRepository.Update(entity);
              

            }
            catch (Exception ex)
            {

                Logger.Error(ex.ToString());
            }
        }
    }

6.设置项目启动项: F5 就可以看到api接口地址及接口描述 

 

 

 

 

 

 

 

posted @ 2019-12-08 19:29  若水如引  阅读(1167)  评论(1编辑  收藏  举报