castle-windsor-ioc-demo
Upcoming SlideShare
Loading in...5
×
 

castle-windsor-ioc-demo

on

  • 871 views

 

Statistics

Views

Total Views
871
Views on SlideShare
871
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

castle-windsor-ioc-demo castle-windsor-ioc-demo Presentation Transcript

  • AMIR BARYLKO IOC INTRO II Using Castle Windsor Anvil Digital Aug 2010Tuesday, August 17, 2010
  • WINDSOR TESTS • Register and Retrieve • Register a particular instance • Register Transient • Constructor resolution • Retrieve with parameters • Retrieve instance by name • Retrieve all instancesTuesday, August 17, 2010
  • ADD WINDSOR CONFIG • Modify Global.asax • // Setup IoC container • this.SetupContainer(); • // Register the factory for the controllers • ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(this.Container));Tuesday, August 17, 2010
  • CONFIGURE WINDSOR • private void SetupContainer() • { • this.Container = new WindsorContainer(); • // add more configuration here • }Tuesday, August 17, 2010
  • ADD CONTROLLERS • Use Name to identify them • They have to be transient • Component.For<MoviesController>().Named ("MoviesController").LifeStyle.Transient, • Component.For<HomeController>().Named ("HomeController").LifeStyle.Transient,Tuesday, August 17, 2010
  • ADD STORAGE • Singleton (default) • Component.For<IMediaLibraryStorage>().Instance(new NHMediaLibraryStorage("c:/temp/movies.db")Tuesday, August 17, 2010
  • ADD MEDIALIBRARY • Singleton (default) • Component • .For<IMediaLibrary() • .ImplementedBy<SimpleMediaLibrary>()Tuesday, August 17, 2010
  • REFACTORING HARD DEPENDENCIES • MoviesController • Hard dependency from MoviesController to create a movie • public ActionResult Create(string title) •{ • this._library.Add(new Movie { Title = title }); • return Redirect("Index"); •}Tuesday, August 17, 2010
  • MOVIE FACTORY • Create class to handle movie creation • public interface IMovieFactory • { • IMovie Create(string title); • }Tuesday, August 17, 2010
  • MOVIES CONTROLLER • Write test • Inject factory in the constructor • Change creation by using the factory • [AcceptVerbs(HttpVerbs.Post)] • public ActionResult Create(string title) • { • this._library.Add(this._factory.Create(title)); • return Redirect("Index"); • }Tuesday, August 17, 2010
  • CONFIGURE CONTAINER • Component.For<IWindsorContainer>() • .Instance(this.Container) • Component.For<IMovieFactory>() • .ImplementedBy<MovieFactory>(), • Component.For<IMovie>() • .ImplementedBy<Movie>() • .LifeStyle.TransientTuesday, August 17, 2010
  • IMPLEMENT FACTORY • public MovieFactory(IWindsorContainer container) • { • _container = container; • } • public IMovie Create(string title) • { • return this._container.Resolve<IMovie>(new Dictionary<string, object>() • { • { "title", title } • }); • }Tuesday, August 17, 2010
  • ADD MOVIE CONSTRUCTOR • public Movie() • { • } • public Movie(string title) • { • this.Title = title; • }Tuesday, August 17, 2010
  • RESOURCES • Src: http://github.com/amirci/IoC-Intro-2 • Windsor: http://using.castleproject.org/display/IoC/Fluent +Registration+API • BDD Intro: http://www.orthocoders.com/Tuesday, August 17, 2010