WPF ToolkitMVVM IOC IServiceConllection

用微软自带的 IOC 需要安装

csharp 复制代码
using Microsoft.Extensions.DependencyInjection;
using System.Configuration;
using System.Data;
using System.Windows;

namespace WpfApp3
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 定义服务通道
        /// </summary>
        public IServiceProvider Services { get; }

        /// <summary>
        /// 设置当前正在使用的App实例
        /// 因为父类Application有这个属性,子类要隐藏父类,需要用new修饰
        /// </summary>
        public new static App Current=> (App)Application.Current;
        public App()
        {
            IServiceCollection sc= new ServiceCollection();
            sc.AddSingleton(typeof(ILog), typeof(Log));
            sc.AddTransient(typeof(MainViewModel));
            this.Services=sc.BuildServiceProvider();
        }
    }

}

案例

相关推荐
竟未曾年少轻狂11 小时前
Spring Boot 项目集成 Redis
java·spring boot·redis·缓存·消息队列·wpf·redis集群
清风~徐~来13 小时前
【视频点播系统】Redis-SDK 介绍及使用
数据库·redis·wpf
棉晗榜13 小时前
WPF DataGrid鼠标滚不动,划不动解决
wpf
baivfhpwxf202314 小时前
wpf自适应布局
wpf
艺杯羹1 天前
Git版本控制深度复盘:从入门到精通的完整指南
git·wpf·版本控制·git学习·git复盘
玄〤2 天前
RabbitMQ 入门篇总结(黑马微服务课day10)(包含黑马商城业务改造)
java·笔记·分布式·spring cloud·微服务·rabbitmq·wpf
向哆哆2 天前
CANN HCCL集合通信库在分布式训练中的高性能通信方案
分布式·wpf·cann
周杰伦fans3 天前
ai-skill开发WPF踩坑
wpf
听麟3 天前
HarmonyOS 6.0+ APP智能快递代收管理系统开发实战:定位追踪与取件提醒落地
深度学习·3d·华为·wpf·harmonyos
棉晗榜3 天前
wpf将svg的多个path数据转为wpf的矢量Path几何图形数据
wpf