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

参照上节

相关推荐
使一颗心免于哀伤17 小时前
《设计模式之禅》笔记摘录 - 21.状态模式
笔记·设计模式
_落纸3 天前
三大基础无源电子元件——电阻(R)、电感(L)、电容(C)
笔记
Alice-YUE3 天前
【CSS学习笔记3】css特性
前端·css·笔记·html
2303_Alpha3 天前
SpringBoot
笔记·学习
萘柰奈3 天前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
沐矢羽3 天前
Tomcat PUT方法任意写文件漏洞学习
学习·tomcat
好奇龙猫3 天前
日语学习-日语知识点小记-进阶-JLPT-N1阶段蓝宝书,共120语法(10):91-100语法+考え方13
学习
向阳花开_miemie3 天前
Android音频学习(十八)——混音流程
学习·音视频
工大一只猿3 天前
51单片机学习
嵌入式硬件·学习·51单片机
c0d1ng3 天前
量子计算学习(第十四周周报)
学习·量子计算