Auto fac的介紹 20131018

  • 76 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
76
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. AutoFac的介紹 Bryan Lin 2013/10/18
  • 2. Agenda  AutoFac 是什麼?  Why AutoFac ?  How to use AutoFac ?  Q&A
  • 3. AutoFac 是什麼?  一種可以讓你的專案使用 Inversion of Controll (IoC)的Framework  使用簡單的方式來實作 IoC,讓程式碼看起來更簡潔  有關dependency injection/inversion of control的說明,可至下列網站參考:  http://martinfowler.com/articles/injection.html
  • 4. Why AutoFac ?  讓程式的測試較為容易進行  保留程式的彈性  在眾多 IoC Framework 中,AutoFac是文件較多,比較容易學習的
  • 5. How to use AutoFac ?  已經有寫好的程式碼如下:
  • 6. How to use AutoFac ?  安裝AutoFac的NuGet包
  • 7. How to use AutoFac ?  使用方式:  要定義類別的 Interface public class SomeType : IService { }
  • 8. 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>();
  • 9. How to use AutoFac ?  以我們剛才的程式碼,我們可以這樣使用:
  • 10. How to use AutoFac ?  接著實作WriteDate這個方法
  • 11. Q&A