多個IoC容器介面卡設計及效能測試和容器選擇

2021-06-11 19:30:16 字數 3880 閱讀 8353

autofac.2.6.3.862

castle.windsor.3.1.0

spring.core.2.0.0

輔助類庫:demo.common.dll

服務介面類庫:demo.lib.dll

oracle元件類庫:demo.lib.oracle.dll

sql元件類庫:demo.lib.sql.dll

using autofac;

using system;

namespace ioc.core.adapter

private icontainer container;

public void prepare()

public t resolve()

public t resolve(string servicename)

public void dispose()

public void register(type tservice, type timplementation, string servicename, lifecycletype lifecycle = lifecycletype.transient)

else

switch (lifecycle)

//if (!string.isnullorempty(servicename))

////else

////container = autofaccontainerbuilder.build();

autofaccontainerbuilder.update(container);}}

public void register(string tservicefull, string timplementationfull, string servicename, lifecycletype lifecycle = lifecycletype.transient)

}public void register(type tservice, type timplementation, lifecycletype lifecycle)

public void register(string tservicefull, string timplementationfull, lifecycletype lifecycle)

register(tservicefull, timplementationfull, servicename, lifecycle);}}

}}

using castle.microkernel.registration;

using castle.windsor;

using system;

using system.collections.generic;

namespace ioc.core.adapter

private windsorcontainer container;

public void prepare()

public t resolve()

public t resolve(string servicename)

public void dispose()

private idictionarynamedict = new dictionary();

public void register(type tservice, type timplementation, string servicename, lifecycletype lifecycle = lifecycletype.transient)

if (!string.isnullorempty(servicename))

container.register(item);}}

public void register(string tservicefull, string timplementationfull, string servicename, lifecycletype lifecycle = lifecycletype.transient)

}public void register(type tservice, type timplementation, lifecycletype lifecycle)

public void register(string tservicefull, string timplementationfull, lifecycletype lifecycle)

register(tservicefull, timplementationfull, servicename, lifecycle);}}

}}

using spring.core;

using spring.context;

using spring.context.support;

using spring.objects.factory.support;

using system;

namespace ioc.core.adapter

public void prepare()

public t resolve()

public t resolve(string servicename)

public void dispose()

public void register(type tservice, type timplementation, string servicename, lifecycletype lifecycle = lifecycletype.transient)

defi.scope = springobjelifecycle;

//建立容器

container.registerobjectdefinition(servicename, defi);}}

public void register(string tservicefull, string timplementationfull, string servicename, lifecycletype lifecycle = lifecycletype.transient)

defi.scope = springobjelifecycle;

string vfullname = type.gettype(timplementationfull).fullname;

//建立容器

autofac略快

spring和windsor略慢,但兩者相差不大

spring和windsor花費時間差不多

autofac比較慢

autofac速度最快,相當穩定

windsor速度居中:是autofac的1~2倍

spring速度最慢: 是autofac的5~6倍左右

容器介面卡(棧容器介面卡 佇列容器介面卡)

我們已有的容器 比如vector list 這個容器支援的操作很多,比如插入,刪除,迭代器訪問等等。而我們希望這個容器表現出來的是棧的樣子 先進後出,入棧出棧等等,此時,我們沒有必要重新動手寫乙個新的資料結構,而是把原來的容器重新封裝一下,改變它的介面,就能把它當做棧使用了。c 定義了三種容器介面卡...

容器介面卡

容器介面卡通常是讓一種已存在的容器型別採用另一種不同的抽象型別的工作方式實現,一般情況下,它的初始化需要傳遞乙個容器作為引數,而它所有的操作也是在這個容器上實現的。標準庫提供了三種順序容器介面卡 stack queue priority queue,使用它們時需要包含 include 和 inclu...

容器介面卡

容器介面卡 stl 中包含三種介面卡 棧stack 佇列queue 和優先順序priority queue 介面卡是容器的介面,它本身不能直接儲存元素,它儲存元素的機制是呼叫另一種順序容器去實現,即可以把介面卡看作 它儲存乙個容器,這個容器再儲存所有元素 stl 中提供的三種介面卡可以由某一種順序容...