Generic and Reflecton

Conditional Resolving multiple implementation from generic interface base on types

articles

Generic type name inside the bracket can be treated as identity of the class

Dependency injection is applied where there is only one implementation to the interface, DI via constructor is mostly seen.

but if a interface has multiple implementation, resolving the right one can be done in runtime and determined by the paramterized type variables

 

[HttpPost]
public IActionResult GetAll([FromBody] GetAllQuery query){var handleType = typeof(IQueryHandler<,>).MakeGenericType(query.GetType(), typeof(List<DemoModel>));dynamic QueryHandler = _context.Resolve(handleType);return new JsonResult(QueryHandler.execute((dynamic)query));}namespace DynamicDI.Query
{public interface IQuery<TResult>{}
}namespace DynamicDI.Query
{public class GetAllQuery : IQuery<List<DemoModel>> {public int Id { get; set; }}
}namespace DynamicDI.QueryHandler
{interface IQueryHandler<IQuery, TResult>{TResult execute(IQuery query);}
}namespace DynamicDI.QueryHandler
{public class GetAllQueryHandler : IQueryHandler<GetAllQuery, List<DemoModel>>{public GetAllQueryHandler(){//Here you can put repository implmentation at the constructor}public List<DemoModel> execute(GetAllQuery query){//repo.getallreturn new List<DemoModel>{new DemoModel{Id=0, Name="Matt"},new DemoModel{Id=1, Name="Yang"}};}}
}

 

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

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

相关文章

Architect - Deployments

Architect - DeploymentsK8S resource monitoring and auto scale https://www.cnblogs.com/Mattcoder/p/11222684.html

YOLOv8 融合 InceptionNeNext 实战:提升小目标与大尺度特征检测能力的架构改进

文章目录 涨点王者:YOLOv8融合InceptionNeXt,小目标检测与大尺度特征捕捉双突破实战教程 一、InceptionNeXt核心:让特征提取“无死角”的架构革命 二、YOLOv8+InceptionNeXt的深度改造:从代码到落地的全流程 1. 自定义InceptionNeXt模块(修改`modules.py`) 2. 注册Incept…

2026年口碑好的GEO搜索优化公司推荐,专业服务全解析 - 工业品牌热点

在AI技术重构信息获取方式的当下,GEO(Generative Engine Optimization)作为连接企业与AI信息入口的关键纽带,正成为品牌抢占流量红利的核心武器。面对市场上良莠不齐的GEO搜索优化公司,如何选择正规GEO推广企业、…

YOLOv8-Pose 全栈部署实践:从模型训练到 RK3588 RKNN 端侧部署

文章目录 【YOLOv8-pose姿态识别部署至RK3588:模型训练到RKNN落地,让人体姿态分析精度与边缘推理速度双突破】 一、项目背景与技术选型:为何选择YOLOv8-pose+RK3588? 二、环境搭建:从代码仓库到硬件适配 1. 源码获取与工程结构 2. 依赖安装与硬件配置 三、YOLOv8-pose模型…

Git 提交后发现作者信息错了,如何安全修复已 push 的历史?

前言 提交并 push 完代码后,发现 Git 的 author name / email 设置错了,导致贡献记录、头像显示异常。 修复思路与步骤(已验证可行)永久修正本地配置(防后续出错) git config user.name "正确用户名" …

Architecture - Security

Architecture - Security

【9*】集合幂级数学习笔记

前言如果你不会集合幂级数,那你就进不了省队。骗你的,会了也不一定能进省队。 长文警告:本文一共 \(1467\) 行,请合理安排阅读时间。 此类知识点大纲中并未涉及,所以【9】是我自己的估计,后带星号表示估计,仅供…

IoU损失函数新突破!Inner-IoU 让 YOLOv11 检测精度显著提升 | 完整实现教程

文章目录 目标检测损失函数革新:Inner-IoU 助力 YOLOv11 精度飙升实战教程 一、Inner-IoU 核心原理:辅助边框如何打破 IoU 瓶颈? 1. 传统 IoU 损失的局限性 2. Inner-IoU 的创新设计:辅助边框的魔力 3. 实验效果:用数据说话 二、Inner-IoU 集成到 YOLOv11 全流程:从代码修…

.Net base software framework - pattern, configuration and tool

.Net base software framework - pattern, configuration and toolPage 21 Genric constraintC# generic constraint is a way to specify requirements on the type parameter of a generic class or method. It allo…

Cloud Connector and Plugin

Cloud Connector and PluginTelecom multi service operator business tool to organize job fullfillment of 10k field repair and install technician 3 self contain microservices - loosely coupling architectu…

YOLOv13 模块改造实战:从零集成 SFSConv 提升目标检测精度(保姆级教程)

零基础手把手教程:在 YOLOv13 中集成 SFSConv,让目标检测更上一层楼 文章目录 零基础手把手教程:在 YOLOv13 中集成 SFSConv,让目标检测更上一层楼 前言 目录 1. 为什么需要 SFSConv?传统 CNN 的局限与高级特征的需求 1.1 传统卷积的特点与不足 1.2 多尺度特征的重要性 1.…

UNet++MobileNetv2模型优化,RK3588部署效率飙升300%

文章目录【保姆级教程】基于UNet&MobileNetv2的语义分割模型从训练到RK3588部署&#xff1a;让边缘AI落地效率提升300%引读一、技术选型与场景价值二、环境搭建&#xff1a;从云端到边缘的工具链闭环1. 云端训练环境&#xff08;Python生态&#xff09;2. 模型转换工具链&a…

处理完ACPI!AcpiBuildRunMethodList链表后返回要检查acpi!AcpiBuildQueueList链表不空运行continue继续循环

处理完ACPI!AcpiBuildRunMethodList链表后返回要检查acpi!AcpiBuildQueueList链表不空运行continue继续循环0: kd> g Breakpoint 5 hit eax00000000 ebx00000000 ecx89906e40 edx00000001 esi89906e30 edi80b019f4 eipf73fb911 espf789ef68 ebpf789ef84 iopl0 nv up…

Angular Interview

Angular InterviewAngular.json just like csproj in c# to defined elements needed to build and run the angular app, it provides application entry point, first view landed, angular defined styles, ts->…

第二次运行ACPI!ACPIBuildProcessQueueList函数链表内的buildRequest->TargetListEntry都是ACPI!AcpiBuildRunMethodList

第二次运行ACPI!ACPIBuildProcessQueueList函数链表内的buildRequest->TargetListEntry都是ACPI!AcpiBuildRunMethodListVOID ACPIBuildDeviceDpc(IN PKDPC Dpc,IN PVOID DpcContext,IN PVOID SystemArgument1,IN PVOID SystemArgument2) {do {//// Assume that…

CSDN首页发布文章请输入文章标题(5~100个字) 还需输入5个字摘要:会在推荐、列表等场景外露,帮助读者快速了解内容,支持一键将正文前 256 字符键入摘要文本框0 / 256A

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

RDBMS interview questions

RDBMS interview questions

攻克低照度检测难题:YOLOv11主干网络增强新方案PE-YOLO详解

购买即可解锁300+YOLO优化文章,并且还有海量深度学习复现项目,价格仅需两杯奶茶的钱,别人有的本专栏也有! 文章目录 YOLOv11低照度增强主干网络PE-YOLO:原理与完整实现教程 算法核心原理 物理模型基础 网络架构设计 完整代码实现 环境配置与依赖 PE模块网络定义 集成PE模…

精度损失1.6%,速度提升10.3 FPS:YOLOv8稀疏训练+Slim剪枝高效压缩方案

剪枝对比 文章目录 slim论文解读:2017年 Slim剪枝(Network Slimming)简介 核心思想 1. **在BatchNorm层中的缩放因子(γ)上引入 L1 正则化** Slim剪枝的步骤 第一步:训练阶段加正则 第二步:通道剪枝 第三步:微调(Fine-tuning) 移植代码 下载yolov8代码 在工作根目录…

完整教程:【Linux】常用指令

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …