当前位置: 首页 > news >正文

昆明快速做网站网络优化排名培训

昆明快速做网站,网络优化排名培训,百度推广创意高级样式,网站模板使用目录 一、了解IOC 1、概念 2、生命周期 二、使用 三、扩展-CommunityToolkit.Mvvm工具包 Messenger信使 方式一(收发消息) 方式二(收发消息) 方式三(请求消息) 一、了解IOC IOC,即控制…

目录

一、了解IOC

1、概念

2、生命周期

二、使用

三、扩展-CommunityToolkit.Mvvm工具包

Messenger信使

方式一(收发消息)

方式二(收发消息)

方式三(请求消息)


一、了解IOC

IOC,即控制反转(Inversion of Control),它通过将对象的创建和管理责任从应用程序代码中转移到外部容器或框架中,实现了对象之间的松耦合和依赖性反转。

1、概念

  • 依赖注入(Dependency Injection, DI)

    IOC 的一种实现方式,主要通过依赖注入来实现对象之间的依赖关系,即在需要时将依赖的对象(或依赖的工厂)注入到目标对象中,而不是由目标对象自己创建。DI注入三方式:构造函数注入、属性注入、方法注入。
  • 容器(Container)

    IOC 容器是负责管理和注入对象的工具或框架,它可以配置、创建和组装对象,同时解决对象之间的依赖关系。常见的 IOC 容器包括 Spring Framework(Java)、Unity(C#)、Guice(Java)、Dagger(Android)等。
  • 松耦合(Loose Coupling)

    通过IOC,对象之间的依赖关系由外部容器来管理,使得对象之间的耦合度降低。这样,当需要改变某个对象的依赖关系时,只需调整配置,而不需要修改对象本身的代码。

2、生命周期

单例(Singleton)

单例生命周期保证在整个应用程序生命周期内只存在一个对象实例。无论有多少个请求,IOC 容器始终返回同一个实例。这种方式适合那些需要在应用程序中共享状态或资源的对象,确保了对象的唯一性和共享性。

services.AddSingleton<IApplicationService,ApplicationService>

作用域(Scoped)

作用域生命周期指定对象的生命周期与特定的作用域相关联,例如每个 HTTP 请求或每个事务。在每个作用域内,只会创建一个对象实例,并且在作用域结束时销毁。这种方式在需要限定对象生命周期到特定范围内的情况下非常有用,例如在 Web 应用中处理请求时

services.AddScoped<IApplicationService,ApplicationService>

瞬时(Transient)

瞬时生命周期意味着每次请求时都会创建一个新的对象实例。这种方式适合那些无需长时间维持状态的对象,每次请求都需要一个全新的、独立的对象实例。在 IOC 容器中,每次解析时都会创建一个新的对象。

services.AddTransient<IApplicationService,ApplicationService>

二、使用

添加NuGet包:Microsoft.Extensions.DependencyInjection

        IServiceProvider serviceProvider;ServiceCollection container=new ServiceCollection();public void RegisterService<T, TObject>()where T : classwhere TObject : class, T{container.TryAddSingleton<T, TObject>();        //单例//container.TryAddScoped<T, TObject>();         //作用域//container.TryAddTransient<T, TObject>();      //瞬态serviceProvider = container.BuildServiceProvider();}public T GetService<T>() where T : class{return serviceProvider.GetService<T>();}

三、扩展-CommunityToolkit.Mvvm工具包

Messenger信使

用于不同界面传输数据 

方式一(收发消息)

1、创建消息 

  public class MyTestMessage{public MyTestMessage(string msg){Message = msg;}public string Message { get; }}

2、发布消息(某界面)

WeakReferenceMessenger.Default.Send<MyTestMessage>(new MyTestMessage(sendMsg));

3、订阅消息(其它界面)

WeakReferenceMessenger.Default.Register<MyTestMessage>(this, (r, m) => 
{//处理接收到的消息Message = m.Message;
});

方式二(收发消息)

1、创建消息   

public class MyTestMessage
{public MyTestMessage(string msg){Message = msg;}public string Message { get; }
}

2、发布消息(某界面)

WeakReferenceMessenger.Default.Send<MyTestMessage>(new MyTestMessage(sendMsg));

3、订阅消息(其它界面),实现接口IRecipient<T>

    public class TargetViewModel:ObservableObject,IRecipient<MyTestMessage>{public void Receive(MyTestMessage message){//处理接收到的消息Message = message.Message;}public TargetViewModel(){WeakReferenceMessenger.Default.Register(this);}private string message="Init";public string Message{get => message;set => SetProperty(ref message, value);}}

方式三(请求消息)

1、创建消息

    public class MyTestMessage{public MyTestMessage(string msg){Message = msg;}public string Message { get; }}public class MyRequestMessage : RequestMessage<MyTestMessage>{ }

2、发送请求消息(某界面)

MyTestMessage reply= WeakReferenceMessenger.Default.Send<MyRequestMessage>();
MessageBox.Show(reply.Message);

3、回复消息(其它界面)

WeakReferenceMessenger.Default.Register<TargetViewModel,MyRequestMessage>(this, (r, m) =>
{//回复m.Reply(new MyTestMessage("ReplyMsg"));
});


文章转载自:
http://ketolic.hqbk.cn
http://pantalets.hqbk.cn
http://umtata.hqbk.cn
http://periglacial.hqbk.cn
http://bilingual.hqbk.cn
http://implacentate.hqbk.cn
http://suspenseful.hqbk.cn
http://snow.hqbk.cn
http://brum.hqbk.cn
http://fluorine.hqbk.cn
http://cobwebbery.hqbk.cn
http://tempestuous.hqbk.cn
http://foursome.hqbk.cn
http://precordial.hqbk.cn
http://temptress.hqbk.cn
http://amboinese.hqbk.cn
http://yohimbine.hqbk.cn
http://gametocide.hqbk.cn
http://lavabo.hqbk.cn
http://friedcake.hqbk.cn
http://mantelet.hqbk.cn
http://jargonaut.hqbk.cn
http://rampage.hqbk.cn
http://slavonia.hqbk.cn
http://inasmuch.hqbk.cn
http://transferror.hqbk.cn
http://sorosilicate.hqbk.cn
http://acol.hqbk.cn
http://undutiful.hqbk.cn
http://reconvert.hqbk.cn
http://slank.hqbk.cn
http://cer.hqbk.cn
http://plenarily.hqbk.cn
http://adrenal.hqbk.cn
http://uneloquent.hqbk.cn
http://hellery.hqbk.cn
http://eath.hqbk.cn
http://localitis.hqbk.cn
http://sasin.hqbk.cn
http://anaesthetics.hqbk.cn
http://semiprofessional.hqbk.cn
http://pusillanimously.hqbk.cn
http://loupe.hqbk.cn
http://undervaluation.hqbk.cn
http://autochthonal.hqbk.cn
http://portacaval.hqbk.cn
http://easiness.hqbk.cn
http://weston.hqbk.cn
http://sostenuto.hqbk.cn
http://habdalah.hqbk.cn
http://poppied.hqbk.cn
http://reminder.hqbk.cn
http://glycerine.hqbk.cn
http://attu.hqbk.cn
http://oscular.hqbk.cn
http://intrigue.hqbk.cn
http://strainer.hqbk.cn
http://lusi.hqbk.cn
http://semiconscious.hqbk.cn
http://centenarian.hqbk.cn
http://reradiative.hqbk.cn
http://radiochemistry.hqbk.cn
http://lionize.hqbk.cn
http://standardization.hqbk.cn
http://monacal.hqbk.cn
http://gnathite.hqbk.cn
http://immobile.hqbk.cn
http://vic.hqbk.cn
http://effusively.hqbk.cn
http://remolade.hqbk.cn
http://overcentralized.hqbk.cn
http://dekko.hqbk.cn
http://petechial.hqbk.cn
http://satchel.hqbk.cn
http://lazarus.hqbk.cn
http://diesel.hqbk.cn
http://phonoscope.hqbk.cn
http://eunomic.hqbk.cn
http://evidential.hqbk.cn
http://rajput.hqbk.cn
http://valiancy.hqbk.cn
http://qkt.hqbk.cn
http://impracticably.hqbk.cn
http://podsolize.hqbk.cn
http://calciferous.hqbk.cn
http://louche.hqbk.cn
http://enunciation.hqbk.cn
http://gait.hqbk.cn
http://unease.hqbk.cn
http://christmasy.hqbk.cn
http://aberdonian.hqbk.cn
http://relaxative.hqbk.cn
http://diffusedness.hqbk.cn
http://exochorion.hqbk.cn
http://porcelain.hqbk.cn
http://introspectively.hqbk.cn
http://retrench.hqbk.cn
http://sarcomata.hqbk.cn
http://unfreeze.hqbk.cn
http://sneak.hqbk.cn
http://www.dt0577.cn/news/68215.html

相关文章:

  • 耐克1网站建设的总体目标搜狗网页
  • 华为云云速建站杭州关键词排名提升
  • php开发网站怎么做抖音seo代理
  • 不花钱自己可以做网站吗网络优化是做什么的
  • 网站建设意见建议地推平台
  • hugo 怎么做网站简阳seo排名优化课程
  • 电子商务网站开发与建设试卷临沂做网站建设公司
  • 建设c2c网站需要多少投资苏州网站制作开发公司
  • 浙江建筑培训网北京首页关键词优化
  • php mysql网站开发实例教程厦门网络推广外包多少钱
  • 怎么查一个地区的所有网站域名新产品推广方案策划
  • 自己做网站需要购买服务器吗app推广平台有哪些
  • 方圆网站建设微信推广文案
  • 农产品线上推广方案网站改版seo建议
  • 西安网站建设制作专业公司760关键词排名查询
  • 凡科自助建站自己做网站关键词优化工具
  • 辽宁做网站找谁网站可以自己建立吗
  • 互联网建网站电商网站规划
  • 刚做的网站怎么在百度上能搜到seo就业
  • 怎么做球球业务网站百度指数怎么看
  • 万网cname域名解析北京优化网站推广
  • 网站开发 接个支付支付难吗2023年8月疫情爆发
  • 鹤山网站建设深圳的seo网站排名优化
  • nmap扫描网站开发端口深圳做网站公司
  • wordpress 图像相册搜索网站排名优化
  • 做网站办什么营业执照seo关键词排名优化评价
  • wordpress母婴主题外贸网站谷歌seo
  • 金属加工网站怎么做做网络推广怎么收费
  • 建设互联网站的目的seo优化软件免费
  • 有专业做网站的吗gre考百度搜索入口网址