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

参照上节

相关推荐
四谎真好看1 分钟前
Java 黑马程序员学习笔记(进阶篇19)
java·笔记·学习·学习笔记
im_AMBER1 小时前
数据结构 06 线性结构
数据结构·学习·算法
新子y1 小时前
【小白笔记】最大交换 (Maximum Swap)问题
笔记·python
你要飞5 小时前
Hexo + Butterfly 博客添加 Live2D 看板娘指南
笔记
Main. 247 小时前
从0到1学习Qt -- 创建第一个Hello World项目
学习
壹号用户8 小时前
python学习之生成器&三者关系
学习
new coder8 小时前
[c++语法学习]Day10:c++引用
开发语言·c++·学习
星域智链8 小时前
宠物智能用品:当毛孩子遇上 AI,是便利还是过度?
人工智能·科技·学习·宠物
ajsbxi8 小时前
【Java 基础】核心知识点梳理
java·开发语言·笔记
呱呱巨基8 小时前
vim编辑器
linux·笔记·学习·编辑器·vim