<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IOC &#8211; Microholmes&#039;s Blog</title>
	<atom:link href="https://www.microholmes.com/category/ioc/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.microholmes.com</link>
	<description>我的知识分享</description>
	<lastBuildDate>Sat, 03 Oct 2020 09:21:04 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>IOC探讨二 &#8211; 场景</title>
		<link>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%ba%8c-%e5%9c%ba%e6%99%af/</link>
					<comments>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%ba%8c-%e5%9c%ba%e6%99%af/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Mon, 14 Sep 2020 14:20:03 +0000</pubDate>
				<category><![CDATA[IOC]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=64</guid>

					<description><![CDATA[IOC探讨二 &#8211; 场景 一、作用域变量 （1）介绍 在网站/API开发时，有记录操作日志、异常日志 [&#8230;]]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="64" class="elementor elementor-64">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-6b178c6 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="6b178c6" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c72c887" data-id="c72c887" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-0f483dc elementor-widget elementor-widget-heading" data-id="0f483dc" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h3 class="elementor-heading-title elementor-size-default">IOC探讨二 - 场景</h3>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-06a7f2a elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="06a7f2a" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1d3710c" data-id="1d3710c" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-7b1b4ec elementor-widget elementor-widget-text-editor" data-id="7b1b4ec" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h4>一、作用域变量</h4><h6>（1）介绍</h6><p>在网站/API开发时，有记录操作日志、异常日志等需求。这时需要统一的记录点，通常日志记录点会与方法分开，比如dotnet core用中间件来记录日志，但此时常常难以取得方法中的一些参数。系统拥有三层架构，但接口的参数往往难以透传到业务层/数据访问层等，中间件也难以取得对应的参数。</p><p>使用DI，可以通过定义作用域，以构造函数注入的方式，将数据透传到需要的任意代码位置，非常类似内存缓存，而且由DI来控制对象的释放、创建，就不需要像控制内存缓存那样，还需要考虑释放对象的时机。</p><h6>（2）代码实例（dotnet core）</h6>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-d070773 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="d070773" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e0ed390" data-id="e0ed390" data-element_type="column">
			<div class="elementor-widget-wrap">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-85d30ae elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="85d30ae" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-78e399b" data-id="78e399b" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-ff366c0 elementor-widget elementor-widget-text-editor" data-id="ff366c0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h4>二、实例化复杂构造函数对象</h4><h6>（1）介绍</h6><p>实际业务编码过程中，可能存在一些构造函数包含多个对象参数的类对象，传统方式在实例化该对象前，需要预先实例化各个参数对象，才能实例化该对象。</p><p>引入DI，则可以直接方便快捷地实例化对象，大大降低代码的复杂度，从某种程度上来说，使代码更为简约优美。</p><h6>（2）代码实例（dotnet core）</h6>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-d90966b elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="d90966b" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0a64405" data-id="0a64405" data-element_type="column">
			<div class="elementor-widget-wrap">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-6aba656 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="6aba656" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a4e5023" data-id="a4e5023" data-element_type="column">
			<div class="elementor-widget-wrap">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3ac2f07 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3ac2f07" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a8e3ba6" data-id="a8e3ba6" data-element_type="column">
			<div class="elementor-widget-wrap">
							</div>
		</div>
					</div>
		</section>
				</div>
		]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%ba%8c-%e5%9c%ba%e6%99%af/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IOC探讨一 &#8211; 概念</title>
		<link>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%b8%80-%e6%a6%82%e5%bf%b5/</link>
					<comments>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%b8%80-%e6%a6%82%e5%bf%b5/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Mon, 14 Sep 2020 01:25:58 +0000</pubDate>
				<category><![CDATA[IOC]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=44</guid>

					<description><![CDATA[IOC探讨一 – 概念 一、什么是IOC？ 控制反转（Inversion of Control），是一种设计思 [&#8230;]]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="44" class="elementor elementor-44">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-2fb6235 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="2fb6235" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b7bdb75" data-id="b7bdb75" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-a457467 elementor-widget elementor-widget-heading" data-id="a457467" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h3 class="elementor-heading-title elementor-size-default">IOC探讨一 – 概念</h3>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-07f22e4 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="07f22e4" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a4bc435" data-id="a4bc435" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-06841d4 elementor-widget elementor-widget-text-editor" data-id="06841d4" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h4>一、什么是IOC？</h4><p>控制反转（Inversion of Control），是一种设计思想。体现了“好莱坞法则”（Hollywood Principle），不要给我们打电话，我们会给你打电话（don‘t call us, we‘ll call you）</p><p>实现IOC的技术手段主要包括：</p><p>（1）DI，Dependency Injection，依赖注入；</p><p>（2）DL，Dependency Lookup，依赖查找。</p><p>其中DL包括：</p><p>（1）DP，Dependency Pull，依赖拖拽；</p><p>（2）CDL，Contextualized Dependency Lookup，上下文依赖查找。</p><h4>二、为什么要用IOC？</h4><p>（1）对象的实例化复杂，实例化一个对象时往往需要同时实例化多个对象，令人头疼；</p><p>（2）IOC可以协助托管对象的实例化和释放，应用程序只需要关心消费即可；</p><p>（3）IOC便于解耦，由容器维护接口的具体对象实现。</p><h4>三、IOC能做什么？</h4><p>（1）解耦程序，方便测试，利于功能复用；</p><p>（2）可以让程序的体系结构变得非常灵活；</p><p>（3）便于数据的透传。</p><h4>四、DI怎么实现(C#/dotnet core)？</h4><p>（1）Constructor Injection，构造器注入</p><p>（2）Setter Injection</p>								</div>
				</div>
				<div class="elementor-element elementor-element-b3ec407 elementor-widget-divider--view-line elementor-widget elementor-widget-divider" data-id="b3ec407" data-element_type="widget" data-widget_type="divider.default">
				<div class="elementor-widget-container">
							<div class="elementor-divider">
			<span class="elementor-divider-separator">
						</span>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-de8caa5 elementor-widget elementor-widget-text-editor" data-id="de8caa5" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><em><strong>参考：</strong></em></p><p><em>[1] <a href="https://blog.csdn.net/ivan820819/article/details/79744797">浅谈IOC&#8211;说清楚IOC是什么</a> ，ivan820819，CSDN，2018-03</em></p><p><em>[2] <a href="https://blog.csdn.net/qq_42709262/article/details/81951402">什么是IOC(控制反转)、DI(依赖注入)</a> ，Ming339456，CSDN，2018-08</em></p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/09/14/ioc%e6%8e%a2%e8%ae%a8%e4%b8%80-%e6%a6%82%e5%bf%b5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
