Download - Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Castle Windsor
Tuna Toksoz
March 24, 2010
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Who am I?
IntroductionDependency InjectionInversion of Control Container
Castle WindsorWhy Castle Windsor?ConfigurationExtensibility points
FacilitiesEventsDependency resolution control mechanismsLifestyle control mechanismsComponent initialization control mechanisms
Conclusion
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Who am I?
I Senior student at Bogazici UniversityI (Passive) committer at Castle and NHibernateI Blogger at his own blog and also on devlicio.usI Has an interest in Robotics and its applications
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
What is DI all about?
I It is a pattern in Martin Fowler’s bookI Depends on the principle of providing dependencies from
the outsideI Made up of 3 components
I DependentI DependencyI Dependency provider
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
Why should we use DI?
I Loosely coupled components/servicesI Increased testabilityI Reduced cost of changes in later stages of developmentI Ability to change implementations between testing and
deployment
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
Why should not we use DI?
I ...
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
Dependency Injection Methods
I Constructor InjectionI Property InjectionI Method Injection
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
Dependency Injection Methods - Examples
I Constructor Injection
I Property Injection
I Method Injection
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Dependency InjectionInversion of Control Container
Inversion of Control Container
I A point where all components are registered and beingaccessed
I A component which resolves dependencies of a requestedcomponent automatically
I Enables us to change implementations without muchtrouble
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Why Castle Windsor?
I A popular frameworkI Active development
I 118 commits between October 2009 and February 2010.I 2nd version
I Extensibility points
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Castle Windsor Configuration
I XML ConfigurationI Fluent ConfigurationI Binsor/Boo Configuration
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
XML Configuration
ConsI Old schoolI Error-prone
ProsI Ability to change without compilation
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Fluent/Programmatic Configuration
ConsI Very hard, if not impossible, to change after compilation
ProsI Compile time checkingI IntellisenseI AllTypes OfI Convention over Configuration
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Fluent/Programmatic Configuration - Cont’d
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Boo/Binsor Configuration
I Compile/Runtime checkingI Intellisense (MonoDevelop)I Easy to change after compilation of applicationI Easier configuration with the help of Boo
extensibility(macros)
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Extensibility points
I FacilitiesI EventsI Dependency resolution control mechanisms
I Subdependency ResolverI Handler SelectorI Interceptor Selector
I Lifestyle control mechanismsI Object initialization control mechanisms
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Facilities
I MK/Windsor’s points of configurationsI A point where a group of related configuration
(microkernel) tasks take place
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Available Facilities
I Active Record IntegrationI Automatic Transaction ManagementI Batch Registration - ObseleteI Event WiringI Factory SupportI Nhibernate IntegrationI SynchronizeI WCF Facility
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Eventler
I ComponentRegisteredI ComponentUnregisteredI ComponentModelCreatedI ComponentCreatedI ComponentDestroyedI DependencyResolvingI and several others
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Eventler - Code
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Dependency resolution control mechanisms
I Subdependency ResolverI Handler SelectorI Interceptor Selector
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Subdependency Resolver
I Tells how¯
a specific dependency of a component should beresolved
I We can either use an existing component or create a newone as the dependency
I Does not affect previously initialized components (MEFcan do it)
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Subdependency Resolver - Code
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Subdependency Resolver - Code 2
Spot the potential problem¯
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Handler Selector
I Allows us to specify what to return as a result of.Resolve<T> calls depending on context
I Does not affect previously initialized components
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Handler Selector - Code
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Interceptor Selector/Interceptor ModelSelector/IProxyGeneration Hook
I Allows us to change cross-cutting concerns at runtimeI We can specify what interceptors should be attachedI Allows us to specify what methods to intercept
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Lifestyle control mechanisms
Decides when¯
to create a componentI SingletonI PerThreadI PerWebRequestI TransientI PoolableI Custom
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Available Lifestyles - Singleton
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Component initialization control mechanisms
Contains the logic related to creation of components. They arecalled Activators in Castle terms.
I Default Activator (The place where dependency injectionbasically takes place)
I Accessor/Factory Activator (Used by Factory SupportFacility)
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Why Castle Windsor?ConfigurationExtensibility points
Component initialization control mechanisms -Accessor Activator
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
DI Advantages
I Reduced cost of changeI Increased testabilityI Allows us to think in terms of component
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Windsor
I A framework that is developed as a result of needsI Easy integration with other frameworksI Active development
Tuna Toksoz Castle Windsor
AgendaWho am I?
IntroductionCastle Windsor
Conclusion
Resources
I http://castleproject.orgI http://groups.google.com/group/castle-project-users/I http://ayende.com
Tuna Toksoz Castle Windsor