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

参照上节

相关推荐
was1724 小时前
你的私有知识库:自托管 Markdown 笔记方案 NoteDiscovery
笔记·云原生·自部署
前路不黑暗@4 小时前
Java项目:Java脚手架项目的文件服务(八)
java·开发语言·spring boot·学习·spring cloud·docker·maven
崎岖Qiu4 小时前
【计算机网络 | 第十一篇】图解交换机的自学习功能
网络·学习·计算机网络
科技林总4 小时前
【系统分析师】8.0 项目管理
学习
浅念-5 小时前
C++ string类
开发语言·c++·经验分享·笔记·学习
Purple Coder5 小时前
基于神经网络的家教系统
学习
foolish..6 小时前
动态规划笔记
笔记·算法·动态规划
victory04317 小时前
LangChain + LangGraph 学习路径
学习·langchain
专业开发者7 小时前
Wi-Fi 技术学习:Wi-Fi 射频设计核心原则 —— 只覆盖你想要的区域
学习
啊哈哈121388 小时前
Python基本语法复盘笔记1(输入输出/字符串/列表)
开发语言·笔记·python