日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Mini 容器学习笔记4——组件的生命周期(应用篇)

發(fā)布時(shí)間:2024/4/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mini 容器学习笔记4——组件的生命周期(应用篇) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Mini容器支持6中生命周期類(lèi)型:

???? 1. Singleton :單利類(lèi)型(缺省組件都是單利類(lèi)型的生命周期,由容器進(jìn)行托管的)

[Test]public void SingletonLifestyleTest(){ServiceRegistry.Register<Person>();var person = ServiceLocator.Get<IPerson>();Assert.IsTrue(person != null);var person2 = ServiceLocator.Get<IPerson>();Assert.IsTrue(person2 != null);Assert.AreSame(person, person2);Assert.IsTrue(Person.HasVisited);} ? 2. Transient:臨時(shí),每次請(qǐng)求組件實(shí)例都返回一個(gè)新的實(shí)例,該實(shí)例不會(huì)被容器托管 [Test]public void TransientLifestyleTest(){ServiceRegistry.Current.Register<IPerson, Person>("person", LifestyleFlags.Transient);var person = ServiceLocator.Get<IPerson>();Assert.IsTrue(person != null);var person2 = ServiceLocator.Get<IPerson>();Assert.IsTrue(person2 != null);Assert.AreNotSame(person, person2);Assert.IsTrue(Person.HasVisited);} ??? 3. Thread:在同一個(gè)線(xiàn)程內(nèi)是單利的 [Test]public void ThreadLifestyleTest(){ServiceRegistry.Current.Register<IPerson, Person>("person", LifestyleFlags.Thread);IPerson person = null,person2 = null, person3 = null, person4 = null;PopulatePerThreadLifestyle(ref person, ref person2);var mre = new ResetEvent(false);ThreadPool.QueueUserWorkItem((s) =>{PopulatePerThreadLifestyle(ref person3, ref person4);mre.Set();});mre.Wait();Assert.AreSame(person, person2);Assert.AreSame(person3, person4);Assert.AreNotSame(person, person3);}private void PopulatePerThreadLifestyle(ref IPerson person, ref IPerson person2){person = ServiceLocator.Get(typeof(IPerson)) as IPerson;Assert.IsTrue(person != null);person2 = ServiceLocator.Get(typeof(IPerson)) as Person;Assert.IsTrue(person2 != null);} 下面三種類(lèi)型是在上面的三種類(lèi)型之上擴(kuò)展來(lái)的 4. GenericSingleton: [Test]public void GenericSingletonLifestyleTest(){ServiceRegistry.Current.Register(typeof(IList<>), typeof(List<>));var instance = ServiceLocator.Get<IList<int>>();Assert.IsNotNull(instance);var instance2 = ServiceLocator.Get<IList<int>>();Assert.IsNotNull(instance2);Assert.AreSame(instance, instance2);} ??????? 5. GenericTransient: [Test]public void GenericTransientLifestyleTest(){ServiceRegistry.Current.Register(new ComponentInfo(null,typeof(IList<>),typeof(List<>), LifestyleFlags.Transient));var instance = ServiceLocator.Get<IList<int>>();Assert.IsNotNull(instance);var instance2 = ServiceLocator.Get<IList<int>>();Assert.IsNotNull(instance2);Assert.AreNotSame(instance, instance2);} ????????? 6. GenericThread: [Test]public void GenericThreadLifestyleTest(){ServiceRegistry.Current.Register(new ComponentInfo(null, typeof(IList<>), typeof(List<>), LifestyleFlags.Thread));IList<int> coll = null,coll2 = null, coll3 = null, coll4 = null;PopulatePerThreadLifestyle(ref coll, ref coll2);var mre = new ResetEvent(false);ThreadPool.QueueUserWorkItem((s) =>{PopulatePerThreadLifestyle(ref coll3, ref coll4);mre.Set();});mre.Wait();Assert.AreSame(coll, coll2);Assert.AreSame(coll3, coll4);Assert.AreNotSame(coll, coll3);}private void PopulatePerThreadLifestyle(ref IList<int> first, ref IList<int> second){first = ServiceLocator.Get(typeof(IList<int>)) as IList<int>;Assert.IsTrue(first != null);second = ServiceLocator.Get(typeof(IList<int>)) as IList<int>;Assert.IsTrue(second != null);} ?

Mini 容器官方網(wǎng)站:

?? ? ??http://nlite.codeplex.com/

推薦資源:

Mini容器介紹

Mini容器學(xué)習(xí)目錄

Mini容器學(xué)習(xí)目錄1——環(huán)境搭建(基礎(chǔ)篇)

Mini 容器學(xué)習(xí)筆記2——組件元數(shù)據(jù)(基礎(chǔ)篇)

Mini 容器學(xué)習(xí)筆記3——組件的注冊(cè)(基礎(chǔ)篇)

Mini 容器學(xué)習(xí)筆記4——組件的生命周期(應(yīng)用篇)

Mini 容器學(xué)習(xí)筆記5——組件的獲取

Mini 容器學(xué)習(xí)筆記6——組件的獲取(應(yīng)用)

Mini 容器學(xué)習(xí)筆記7——構(gòu)造函數(shù)注入

Mini 容器學(xué)習(xí)筆記8——字段注入

Mini 容器學(xué)習(xí)筆記9——屬性注入

Mini 容器學(xué)習(xí)筆記10——方法注入

Mini 容器學(xué)習(xí)筆記11——Lazy注入

Mini 容器學(xué)習(xí)筆記12——組合實(shí)例

Mini 容器學(xué)習(xí)筆記13——插件注入

Mini 容器學(xué)習(xí)筆記14——異常處理

Mini 容器學(xué)習(xí)筆記15——監(jiān)聽(tīng)器-初始化監(jiān)聽(tīng)器

Mini 容器學(xué)習(xí)筆記16——監(jiān)聽(tīng)器-釋放監(jiān)聽(tīng)器

Mini 容器學(xué)習(xí)筆記17——監(jiān)聽(tīng)器-啟動(dòng)/停止監(jiān)聽(tīng)器

Mini 容器學(xué)習(xí)筆記18——監(jiān)聽(tīng)器-AOP監(jiān)聽(tīng)器

轉(zhuǎn)載于:https://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772085.html

總結(jié)

以上是生活随笔為你收集整理的Mini 容器学习笔记4——组件的生命周期(应用篇)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。