SlideShare uma empresa Scribd logo
1 de 11
AutoFac的介紹
Bryan Lin
2013/10/18
Agenda


AutoFac 是什麼?



Why AutoFac ?



How to use AutoFac ?



Q&A
AutoFac 是什麼?


一種可以讓你的專案使用 Inversion of Controll (IoC)的Framework



使用簡單的方式來實作 IoC,讓程式碼看起來更簡潔



有關dependency injection/inversion of control的說明,可至下列網站參考:


http://martinfowler.com/articles/injection.html
Why AutoFac ?


讓程式的測試較為容易進行



保留程式的彈性



在眾多 IoC Framework 中,AutoFac是文件較多,比較容易學習的
How to use AutoFac ?


已經有寫好的程式碼如下:
How to use AutoFac ?


安裝AutoFac的NuGet包
How to use AutoFac ?


使用方式:


要定義類別的 Interface

public class SomeType : IService
{
}
How to use AutoFac ?


建立 ContainerBuilder 來註冊 IoC 的類別

// Create your builder.
var builder = new ContainerBuilder();
// Usually you're only interested in exposing the type
// via its interface:
builder.RegisterType<SomeType>().As<IService>();
// However, if you want BOTH services (not as common)
// you can say so:
builder.RegisterType<SomeType>().AsSelf().As<IService>();
How to use AutoFac ?


以我們剛才的程式碼,我們可以這樣使用:
How to use AutoFac ?


接著實作WriteDate這個方法
Q&A

Mais conteúdo relacionado

Destaque

20150724 jason winston js
20150724 jason winston js20150724 jason winston js
20150724 jason winston jsLearningTech
 
20120518 power shell_文字處理及輕量測試
20120518 power shell_文字處理及輕量測試20120518 power shell_文字處理及輕量測試
20120518 power shell_文字處理及輕量測試LearningTech
 
Ken - caman.js,SoundManager2.js,CSS3 Animations
Ken - caman.js,SoundManager2.js,CSS3 AnimationsKen - caman.js,SoundManager2.js,CSS3 Animations
Ken - caman.js,SoundManager2.js,CSS3 AnimationsLearningTech
 
20130719 Howard_下載檔案的五四三
20130719 Howard_下載檔案的五四三20130719 Howard_下載檔案的五四三
20130719 Howard_下載檔案的五四三LearningTech
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115LearningTech
 
20151120 ian cocos2d js
20151120 ian cocos2d js20151120 ian cocos2d js
20151120 ian cocos2d jsLearningTech
 
20121228 jQueryui - dialog - By Drake
20121228 jQueryui - dialog - By Drake20121228 jQueryui - dialog - By Drake
20121228 jQueryui - dialog - By DrakeLearningTech
 
Expression 的介紹及應用
Expression 的介紹及應用Expression 的介紹及應用
Expression 的介紹及應用LearningTech
 
Power shell – scriptblock
Power shell – scriptblockPower shell – scriptblock
Power shell – scriptblockLearningTech
 

Destaque (17)

20150724 jason winston js
20150724 jason winston js20150724 jason winston js
20150724 jason winston js
 
20120518 power shell_文字處理及輕量測試
20120518 power shell_文字處理及輕量測試20120518 power shell_文字處理及輕量測試
20120518 power shell_文字處理及輕量測試
 
Ken - caman.js,SoundManager2.js,CSS3 Animations
Ken - caman.js,SoundManager2.js,CSS3 AnimationsKen - caman.js,SoundManager2.js,CSS3 Animations
Ken - caman.js,SoundManager2.js,CSS3 Animations
 
20130719 Howard_下載檔案的五四三
20130719 Howard_下載檔案的五四三20130719 Howard_下載檔案的五四三
20130719 Howard_下載檔案的五四三
 
Bcp
BcpBcp
Bcp
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
 
20151120 ian cocos2d js
20151120 ian cocos2d js20151120 ian cocos2d js
20151120 ian cocos2d js
 
Angular module
Angular moduleAngular module
Angular module
 
20121228 jQueryui - dialog - By Drake
20121228 jQueryui - dialog - By Drake20121228 jQueryui - dialog - By Drake
20121228 jQueryui - dialog - By Drake
 
Expression 的介紹及應用
Expression 的介紹及應用Expression 的介紹及應用
Expression 的介紹及應用
 
Power shell – scriptblock
Power shell – scriptblockPower shell – scriptblock
Power shell – scriptblock
 
Peggy - XPath
Peggy - XPathPeggy - XPath
Peggy - XPath
 
SignalR
SignalRSignalR
SignalR
 
Kockout
KockoutKockout
Kockout
 
Powershell enum
Powershell enumPowershell enum
Powershell enum
 
mongoose
mongoosemongoose
mongoose
 
R language
R languageR language
R language
 

Semelhante a Auto fac的介紹 20131018

安博士Asec 2010年7月安全报告
安博士Asec 2010年7月安全报告安博士Asec 2010年7月安全报告
安博士Asec 2010年7月安全报告ahnlabchina
 
Phalcon2014 Startup
Phalcon2014 StartupPhalcon2014 Startup
Phalcon2014 StartupSteve Luo
 
Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談Yu-Wei Chuang
 
安博士Asec 2010年4月安全报告
安博士Asec 2010年4月安全报告安博士Asec 2010年4月安全报告
安博士Asec 2010年4月安全报告ahnlabchina
 
淘宝彩票移动项目开发实践
淘宝彩票移动项目开发实践淘宝彩票移动项目开发实践
淘宝彩票移动项目开发实践alvis-m
 
CodeIgniter 2.0.X
CodeIgniter 2.0.XCodeIgniter 2.0.X
CodeIgniter 2.0.XBo-Yi Wu
 
GAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannelGAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannelSimon Su
 
基于协程的网络开发框架的设计与实现
基于协程的网络开发框架的设计与实现基于协程的网络开发框架的设计与实现
基于协程的网络开发框架的设计与实现mysqlops
 
常用开发工具介绍
常用开发工具介绍常用开发工具介绍
常用开发工具介绍haozes
 
腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介areyouok
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Wade Huang
 
Flex 4.5 action custom component development
Flex 4.5 action custom component developmentFlex 4.5 action custom component development
Flex 4.5 action custom component developmentjexchan
 
Spring boot 简介
Spring boot 简介Spring boot 简介
Spring boot 简介宇帆 盛
 
Clojure cnclojure-meetup
Clojure cnclojure-meetupClojure cnclojure-meetup
Clojure cnclojure-meetupsunng87
 
Better use angular
Better use angularBetter use angular
Better use angularYanru Li
 
J frog live demo ver4
J frog live demo   ver4J frog live demo   ver4
J frog live demo ver4Linktech
 
价值中国网站开发、管理经验探讨、分享、交流
价值中国网站开发、管理经验探讨、分享、交流价值中国网站开发、管理经验探讨、分享、交流
价值中国网站开发、管理经验探讨、分享、交流hizhubo
 
Er introduction
Er introductionEr introduction
Er introductionYubei Li
 

Semelhante a Auto fac的介紹 20131018 (20)

安博士Asec 2010年7月安全报告
安博士Asec 2010年7月安全报告安博士Asec 2010年7月安全报告
安博士Asec 2010年7月安全报告
 
Phalcon2014 Startup
Phalcon2014 StartupPhalcon2014 Startup
Phalcon2014 Startup
 
Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談
 
安博士Asec 2010年4月安全报告
安博士Asec 2010年4月安全报告安博士Asec 2010年4月安全报告
安博士Asec 2010年4月安全报告
 
Bluemix API Connect
Bluemix API ConnectBluemix API Connect
Bluemix API Connect
 
Bluemix Api Connect
Bluemix Api ConnectBluemix Api Connect
Bluemix Api Connect
 
淘宝彩票移动项目开发实践
淘宝彩票移动项目开发实践淘宝彩票移动项目开发实践
淘宝彩票移动项目开发实践
 
CodeIgniter 2.0.X
CodeIgniter 2.0.XCodeIgniter 2.0.X
CodeIgniter 2.0.X
 
GAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannelGAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannel
 
基于协程的网络开发框架的设计与实现
基于协程的网络开发框架的设计与实现基于协程的网络开发框架的设计与实现
基于协程的网络开发框架的设计与实现
 
常用开发工具介绍
常用开发工具介绍常用开发工具介绍
常用开发工具介绍
 
腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
 
Flex 4.5 action custom component development
Flex 4.5 action custom component developmentFlex 4.5 action custom component development
Flex 4.5 action custom component development
 
Spring boot 简介
Spring boot 简介Spring boot 简介
Spring boot 简介
 
Clojure cnclojure-meetup
Clojure cnclojure-meetupClojure cnclojure-meetup
Clojure cnclojure-meetup
 
Better use angular
Better use angularBetter use angular
Better use angular
 
J frog live demo ver4
J frog live demo   ver4J frog live demo   ver4
J frog live demo ver4
 
价值中国网站开发、管理经验探讨、分享、交流
价值中国网站开发、管理经验探讨、分享、交流价值中国网站开发、管理经验探讨、分享、交流
价值中国网站开发、管理经验探讨、分享、交流
 
Er introduction
Er introductionEr introduction
Er introduction
 

Mais de LearningTech

Mais de LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Auto fac的介紹 20131018