WPF实战学习笔记15-使用Memo类的GetAll接口

使用Memo类的GetAll接口

总体参照上节即可

创建MemoService接口

新建文件Mytodo/Service/IMemoService.cs

c# 复制代码
using MyToDo.Share.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Service
{
    public interface IMemoService : IBaseService<MemoDto>
    {
    }
}

实现MemoService接口

新建文件Mytodo/Service/MemoService.cs

c# 复制代码
using MyToDo.Share.Contact;
using MyToDo.Share.Models;
using MyToDo.Share.Parameters;
using MyToDo.Share;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Service
{
    public class MemoService : BaseService<MemoDto>,IMemoService
    {
        private readonly HttpRestClient client;

        public MemoService(HttpRestClient client) : base(client, "Memo")
        {
            this.client = client;
        }

        public async Task<ApiResponse<PagedList<MemoDto>>> GetAllFilterAsync(MemoParameter parameter)
        {
            BaseRequest request = new BaseRequest();

            request.Method = RestSharp.Method.Get;

            request.Route = $"api/Memo/GetAll?PageIndex={parameter.PageIndex}" +
                $"&PageSize={parameter.PageSize}" +
                $"&search={parameter.Search}" +
                $"&status={parameter.Status}";

            return await client.ExecuteAsync<PagedList<MemoDto>>(request);
        }

    }
}

依赖注入

修改 文件:Mytodo/App.xaml.cs

部分修改为:

复制代码
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{

    //注册服务
    containerRegistry.GetContainer().Register<HttpRestClient>(made: Parameters.Of.Type<string>(serviceKey: "webUrl"));
    containerRegistry.GetContainer().RegisterInstance(@"Http://localhost:19007/", serviceKey: "webUrl");

    containerRegistry.Register<ITodoService, TodoService>();
    containerRegistry.Register<IMemoService, MemoService>();

    containerRegistry.RegisterForNavigation<AboutView, AboutViewModel>();
    containerRegistry.RegisterForNavigation<SysSetView, SysSetViewModel>();
    containerRegistry.RegisterForNavigation<SkinView, SkinViewModel>();
    containerRegistry.RegisterForNavigation<IndexView, IndexViewModel>();
    containerRegistry.RegisterForNavigation<TodoView, TodoViewModel>();
    containerRegistry.RegisterForNavigation<MemoView, MemoViewModel>();
    containerRegistry.RegisterForNavigation<SettingsView, SettingsViewModel>();
}

修改ViewModel

参照上节

相关推荐
西岭千秋雪_12 小时前
Zookeeper实现分布式锁
java·分布式·后端·zookeeper·wpf
im_AMBER16 小时前
React 17
前端·javascript·笔记·学习·react.js·前端框架
报错小能手16 小时前
C++笔记——STL map
c++·笔记
谷歌开发者17 小时前
Web 开发指向标 | Chrome 开发者工具学习资源 (六)
前端·chrome·学习
lkbhua莱克瓦2418 小时前
Java基础——集合进阶3
java·开发语言·笔记
QT 小鲜肉18 小时前
【QT/C++】Qt定时器QTimer类的实现方法详解(超详细)
开发语言·数据库·c++·笔记·qt·学习
MeowKnight95818 小时前
【Qt】Qt实践记录3——UDP通信
笔记·qt
REDcker18 小时前
前端打包工具 - Rollup 打包工具笔记
前端·笔记
lkbhua莱克瓦2419 小时前
Java基础——集合进阶用到的数据结构知识点1
java·数据结构·笔记·github
Mr.Jessy19 小时前
Web APIs 学习第五天:日期对象与DOM节点
开发语言·前端·javascript·学习·html