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

参照上节

相关推荐
2501_918126912 小时前
stm32做一个次声波检测器,需要哪些元件
stm32·单片机·嵌入式硬件·学习·个人开发
GocNeverGiveUp2 小时前
大模型学习2-Agent
学习
Bal炎魔3 小时前
AI 学习专题一,AI 实现的原理
人工智能·学习
Ro Jace3 小时前
分岔机制学习
人工智能·学习·机器学习
雾岛听蓝4 小时前
C++11新特性(lambda、包装器)
c++·经验分享·笔记
反向跟单策略4 小时前
期货反向跟单-2025年回顾及2026年展望
大数据·人工智能·学习·数据分析·区块链
yunhuibin5 小时前
GoogLeNet学习
人工智能·python·深度学习·神经网络·学习
xcLeigh6 小时前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
知识分享小能手6 小时前
PostgreSQL 入门学习教程,从入门到精通,PostgreSQL 16 语法知识点与案例详解(1)
数据库·学习·postgresql
代码游侠6 小时前
Linux驱动复习——驱动
linux·运维·arm开发·笔记·学习