兰州新区建设银行网站简述软件开发流程

news/2025/9/23 23:21:24/文章来源:
兰州新区建设银行网站,简述软件开发流程,普通网站和营销型网站的区别是什么,电销系统线路本文内容 先决条件创建新的控制台应用程序添加接口添加默认实现添加需要 DI 的服务为 DI 注册服务结束语 本文介绍如何在 .NET 中使用依赖注入 (DI)。 借助 Microsoft 扩展#xff0c;可通过添加服务并在 IServiceCollection 中配置这些服务来管理 DI。 IHost 接口会公开 IS…本文内容 先决条件创建新的控制台应用程序添加接口添加默认实现添加需要 DI 的服务为 DI 注册服务结束语 本文介绍如何在 .NET 中使用依赖注入 (DI)。 借助 Microsoft 扩展可通过添加服务并在 IServiceCollection 中配置这些服务来管理 DI。 IHost 接口会公开 IServiceProvider 实例它充当所有已注册的服务的容器。 本文介绍如何执行下列操作 创建一个使用依赖注入的 .NET 控制台应用生成和配置通用主机编写多个接口及相应的实现为 DI 使用服务生存期和范围设定 1、先决条件 .NET Core 3.1 SDK 或更高版本。熟悉如何创建新的 .NET 应用程序以及如何安装 NuGet 包。 2、创建新的控制台应用程序 通过 dotnet new 命令或 IDE 的“新建项目”向导新建一个名为 ConsoleDI 的 .NET 控制台应用程序 Example 。 将 NuGet 包 Microsoft.Extensions.Hosting 添加到项目。 新的控制台应用项目文件应如下所示 Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet7.0/TargetFrameworkNullableenable/NullableImplicitUsingstrue/ImplicitUsingsRootNamespaceConsoleDI.Example/RootNamespace/PropertyGroupItemGroupPackageReference IncludeMicrosoft.Extensions.Hosting Version7.0.1 //ItemGroup/Project重要 在此示例中需要 NuGet 包 Microsoft.Extensions.Hosting 来生成和运行应用。 某些元包可能包含 Microsoft.Extensions.Hosting 包在这种情况下不需要显式包引用。 3、添加接口 在此示例应用中你将了解依赖项注入如何处理服务生存期。 你将创建多个表示不同服务生存期的接口。 将以下接口添加到项目根目录 IReportServiceLifetime.cs using Microsoft.Extensions.DependencyInjection;namespace ConsoleDI.Example;public interface IReportServiceLifetime {Guid Id { get; }ServiceLifetime Lifetime { get; } }IReportServiceLifetime 接口定义了以下项 表示服务的唯一标识符的 Guid Id 属性。表示服务生存期的 ServiceLifetime 属性。 IExampleTransientService.cs using Microsoft.Extensions.DependencyInjection;namespace ConsoleDI.Example;public interface IExampleTransientService : IReportServiceLifetime {ServiceLifetime IReportServiceLifetime.Lifetime ServiceLifetime.Transient; }IExampleScopedService.cs using Microsoft.Extensions.DependencyInjection;namespace ConsoleDI.Example;public interface IExampleScopedService : IReportServiceLifetime {ServiceLifetime IReportServiceLifetime.Lifetime ServiceLifetime.Scoped; }IExampleSingletonService.cs using Microsoft.Extensions.DependencyInjection;namespace ConsoleDI.Example;public interface IExampleSingletonService : IReportServiceLifetime {ServiceLifetime IReportServiceLifetime.Lifetime ServiceLifetime.Singleton; }IReportServiceLifetime 的所有子接口均使用默认值显式实现 IReportServiceLifetime.Lifetime。 例如IExampleTransientService 使用 ServiceLifetime.Transient 值显式实现 IReportServiceLifetime.Lifetime。 4、添加默认实现 该示例实现使用 Guid.NewGuid() 的结果初始化其 Id 属性。 将各种服务的下列默认实现类添加到项目根目录 ExampleTransientService.cs namespace ConsoleDI.Example;internal sealed class ExampleTransientService : IExampleTransientService {Guid IReportServiceLifetime.Id { get; } Guid.NewGuid(); }ExampleScopedService.cs namespace ConsoleDI.Example;internal sealed class ExampleScopedService : IExampleScopedService {Guid IReportServiceLifetime.Id { get; } Guid.NewGuid(); }ExampleSingletonService.cs namespace ConsoleDI.Example;internal sealed class ExampleSingletonService : IExampleSingletonService {Guid IReportServiceLifetime.Id { get; } Guid.NewGuid(); }每个实现都定义为 internal sealed 并实现其相应的接口。 例如ExampleSingletonService 会实现 IExampleSingletonService。 5、添加需要 DI 的服务 添加下列服务生存期报告器类它作为服务添加到控制台应用 ServiceLifetimeReporter.cs namespace ConsoleDI.Example;internal sealed class ServiceLifetimeReporter {private readonly IExampleTransientService _transientService;private readonly IExampleScopedService _scopedService;private readonly IExampleSingletonService _singletonService;public ServiceLifetimeReporter(IExampleTransientService transientService,IExampleScopedService scopedService,IExampleSingletonService singletonService) (_transientService, _scopedService, _singletonService) (transientService, scopedService, singletonService);public void ReportServiceLifetimeDetails(string lifetimeDetails){Console.WriteLine(lifetimeDetails);LogService(_transientService, Always different);LogService(_scopedService, Changes only with lifetime);LogService(_singletonService, Always the same);}private static void LogServiceT(T service, string message)where T : IReportServiceLifetime Console.WriteLine($ {typeof(T).Name}: {service.Id} ({message})); }ServiceLifetimeReporter 会定义一个构造函数该函数需要上述每一个服务接口即 IExampleTransientService、IExampleScopedService 和 IExampleSingletonService。 对象会公开一个方法使用者可通过该方法使用给定的 lifetimeDetails 参数报告服务。 被调用时ReportServiceLifetimeDetails 方法会使用服务生存期消息记录每个服务的唯一标识符。 日志消息有助于直观呈现服务生存期。 6、为 DI 注册服务 使用以下代码更新 Program.cs using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using ConsoleDI.Example;HostApplicationBuilder builder Host.CreateApplicationBuilder(args);builder.Services.AddTransientIExampleTransientService, ExampleTransientService(); builder.Services.AddScopedIExampleScopedService, ExampleScopedService(); builder.Services.AddSingletonIExampleSingletonService, ExampleSingletonService(); builder.Services.AddTransientServiceLifetimeReporter();using IHost host builder.Build();ExemplifyServiceLifetime(host.Services, Lifetime 1); ExemplifyServiceLifetime(host.Services, Lifetime 2);await host.RunAsync();static void ExemplifyServiceLifetime(IServiceProvider hostProvider, string lifetime) {using IServiceScope serviceScope hostProvider.CreateScope();IServiceProvider provider serviceScope.ServiceProvider;ServiceLifetimeReporter logger provider.GetRequiredServiceServiceLifetimeReporter();logger.ReportServiceLifetimeDetails(${lifetime}: Call 1 to provider.GetRequiredServiceServiceLifetimeReporter());Console.WriteLine(...);logger provider.GetRequiredServiceServiceLifetimeReporter();logger.ReportServiceLifetimeDetails(${lifetime}: Call 2 to provider.GetRequiredServiceServiceLifetimeReporter());Console.WriteLine(); }每个 services.Add{LIFETIME}{SERVICE} 扩展方法添加并可能配置服务。 我们建议应用遵循此约定。 将扩展方法置于 Microsoft.Extensions.DependencyInjection 命名空间中以封装服务注册的组。 还包括用于 DI 扩展方法的命名空间部分 Microsoft.Extensions.DependencyInjection 允许在不添加其他 using 块的情况下在 IntelliSense 中显示它们。在通常会调用这些扩展方法的 Program 或 Startup 类中避免出现过多的 using 语句。 应用会执行以下操作 使用默认活页夹设置创建一个 IHostBuilder 实例。配置服务并对其添加相应的服务生存期。调用 Build() 并分配 IHost 的实例。调用 ExemplifyScoping传入 IHost.Services。 7、结束语 在此示例应用中你创建了多个接口和相应的实现。 其中每个服务都唯一标识并与 ServiceLifetime 配对。 示例应用演示了如何针对接口注册服务实现以及如何在没有支持接口的情况下注册纯类。 然后示例应用演示了如何在运行时解析定义为构造函数参数的依赖项。 运行该应用时它会显示如下所示的输出 // Sample output: // Lifetime 1: Call 1 to provider.GetRequiredServiceServiceLifetimeReporter() // IExampleTransientService: d08a27fa-87d2-4a06-98d7-2773af886125 (Always different) // IExampleScopedService: 402c83c9-b4ed-4be1-b78c-86be1b1d908d (Changes only with lifetime) // IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same) // ... // Lifetime 1: Call 2 to provider.GetRequiredServiceServiceLifetimeReporter() // IExampleTransientService: b43d68fb-2c7b-4a9b-8f02-fc507c164326 (Always different) // IExampleScopedService: 402c83c9-b4ed-4be1-b78c-86be1b1d908d (Changes only with lifetime) // IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same) // // Lifetime 2: Call 1 to provider.GetRequiredServiceServiceLifetimeReporter() // IExampleTransientService: f3856b59-ab3f-4bbd-876f-7bab0013d392 (Always different) // IExampleScopedService: bba80089-1157-4041-936d-e96d81dd9d1c (Changes only with lifetime) // IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same) // ... // Lifetime 2: Call 2 to provider.GetRequiredServiceServiceLifetimeReporter() // IExampleTransientService: a8015c6a-08cd-4799-9ec3-2f2af9cbbfd2 (Always different) // IExampleScopedService: bba80089-1157-4041-936d-e96d81dd9d1c (Changes only with lifetime) // IExampleSingletonService: a61f1ff4-0b14-4508-bd41-21d852484a7b (Always the same)在应用输出中可看到 Transient 服务总是不同的每次检索服务时都会创建一个新实例。Scoped 服务只会随着新范围而改变但在一个范围中是相同的实例。Singleton 服务总是相同的新实例仅被创建一次。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914209.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深圳网站建设lxhd家政服务网站做推广有效果吗

KB2919442 下载地址:https://www.microsoft.com/zh-cn/download/confirmation.aspx?id42153 KB2919355 下载地址:https://www.microsoft.com/zh-cn/download/confirmation.aspx?id42153 安装步骤:先安装442,后安装355

盘锦做网站的公司wordpress网站地图提交

参考资料:生物统计学 https://real-statistics.com/one-way-analysis-of-variance-anova/unplanned-comparisons/tukey-hsd/ Tukey法是基于学生化极差分布计算最小显著极差(LSR),根据平均数个数调整最小显著极差。 LSR&#xff1…

如何做微信小程序步骤深圳网站优化团队

1.忍受大法 第一种解决办法,很简单,无他,不管他,没有读到也没事。这时业务不需要任何改造,你好,我好,她也好~ 如果业务对于数据一致性要求不高,我们就可以采用这种方案。 2.数据同…

加强网站队伍建设建站平台软件

时间数据类型 1.mongo中存储时间大多为ISOData 2.获取当前时间   1. 使用new Date() 自动生成当前时间   2. 使用 ISODate() 生成当前时间   3. 获取计算机时间生成时间格式字符串 Date() 3.ISODate()   功能: 生成mongodb时间存储类型   参数&#xff1a…

做网站个网站要多少钱中国企业网站开发

爬虫专栏:http://t.csdnimg.cn/WfCSx 前言 在前一章中,我们了解了 Ajax 的分析和抓取方式,这其实也是 JavaScript 动态渲染的页面的一种情形,通过直接分析 Ajax,我们仍然可以借助 requests 或 urllib 来实现数据爬取…

广东品牌网站设计专家鹿寨建设局网站

本次实验将采用docker部署zabbix 5.2平台监控ESXI 6.5虚拟化系统—————————————————————————— 请自行准备环境: 关于docker部署方案请参考: docker之核心概念与安装 关于docker部署zabbix方案请参考: docker容器方式部署zabbix监控平台 关于ESXI安…

网站建设完成后期维护网站的seo

前言:本文会介绍 Android 与 iOS 两个平台的处理方式 一、Android高版本在应用退到后台时,系统为了省电会限制应用的后台活动,因此我们需要开启一个前台服务,在前台服务中发送常驻任务栏通知,以此来保证App 退到后台时不会被限制活动. 前台服务代码如下: package com.notify…

长春市长春网站建设高端型网站制作

什么是 resolvectl “resolvectl” 是一个用于管理系统 DNS 解析配置的命令行工具。它是 systemd-resolved 服务的一部分,该服务是在许多基于 Systemd 的 Linux 发行版中用于管理网络配置和 DNS 解析的系统服务。 通过 resolvectl 命令,可以查看当前系…

建设银行官方网站首页入口购物网站排名大全

题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果。 如果是返回true,否则返回false。 例如输入5、7、6、9、11、10、8,由于这一整数序列是如下树的后序遍历结果: 8 / \ 6 10 / \ / \ 5 7 9…

平台类网站有哪些广州市网站开发

-- 日、时、分、秒,这是计时的单位,惜时就应该惜日、惜时、惜分、惜秒。 用 Java 来读取 Excel 文件,检查每一行中的 URL,并将不符合条件的行标记为红色。以下是一个简单的示例,使用 Apache POI 进行 Excel 操作&#…

02020405 EF Core基础05-EF Core反向工程、EF Core和ADO.NET Core的联系、EF Core无法做到的事情

02020405 EF Core基础05-EF Core反向工程、EF Core和ADO.NET Core的联系、EF Core无法做到的事情 1. 数据库设计的三种形式(视频3-9)DB First → 先在数据库中将数据表建好了,然后再反向生成实体类。简单,但是不适…

02020406 EF Core基础06-EF Core生成的SQL

02020406 EF Core基础06-EF Core生成的SQL 1. 通过代码查看EF Core的SQL语句(视频3-12) 1.1 方法1:标准日志 // 标准日志用法示例 public static readonly ILoggerFactory MyLoggerFactory= LoggerFactory.Create(b…

北京网站建设工作南京专业做网站的公司有哪些

面试中的收获: 优点: 1. 设计用例考虑较为全面。 2. 自动化,性能都有涉猎,但不深入。 3. 对业务理解较深入。 缺点: 1. 接口自动化停留在初级阶段。 2. UI自动化了解较少。 3. 性能压测缺少数据清洗等步骤。 4. 算法还…

菲斯曼售后服务中心贵港seo关键词整站优化

拦截器-interceptor 在现代的一些前端框架上,拦截器基本上是很基础但很重要的一环,比如Angular原生就支持拦截器配置,VUE的Axios模块也给我们提供了拦截器配置,那么拦截器到底是什么,它有什么用?拦截器能帮…

网站打不开服务器错误建手机网站多少钱

给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用一次。 说明: 所有数字(包括目标数)都是正整数。解集不能包含重复的组合。 …

温州专业网站建设公司wordpress的链接怎么设置

把这个项目的文档迁入到SVN Server上的库中 【1】首先右键点击projectAdmin目录,这时候的右键菜单例如以下图看到的:选择copy URL toCLipboard,就是复制统一资源定位符(URL)到剪贴板中 https://KJ-AP01.中国.corpnet:8443/svn/pro…

中山建设监理有限公司 网站扁平化网站首页

随着数字化时代的来临,装修小程序成为提升服务质量和效率的关键工具。装修小程序旨在为装修公司提供数字化赋能、提高客户满意度的智慧装修平台。通过装修小程序,装修公司能够与客户进行在线沟通、展示设计方案、提高服务满意度等操作。 装修小程序的好处…

服装商城网站模板wordpress极简模板

前言 整理这个官方翻译的系列,原因是网上大部分的 tomcat 版本比较旧,此版本为 v11 最新的版本。 开源项目 从零手写实现 tomcat minicat 别称【嗅虎】心有猛虎,轻嗅蔷薇。 系列文章 web server apache tomcat11-01-官方文档入门介绍 web…

网站编程培训班开发微信商城平台

串的概念:串(字符串):是由 0 个或多个字符组成的有限序列。 通常记为:s ‘ a1 a2 a3 … ai …an ’ ( n≥0 )。 串的逻辑结构和线性表极为相似。 一些串的类型: 空串:不含任何字符的串&#x…