SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
AMIR BARYLKO

                    ADVANCED IOC
                      WINDSOR
                       CASTLE



Amir Barylko - Advanced IoC              MavenThought Inc.
FIRST STEPS
                                Why IoC containers
                              Registering Components
                                      LifeStyles
                                       Naming



Amir Barylko - Advanced IoC                            MavenThought Inc.
WHY USE IOC

  • Manage           creation and disposing objects
  • Avoid        hardcoding dependencies
  • Dependency                injection
  • Dynamically               configure instances
  • Additional            features
Amir Barylko - Advanced IoC                           MavenThought Inc.
REGISTRATION

  • In   order to resolve instances, we need to register them
  Container.Register(
         // Movie class registered
         Component.For<Movie>(),


         // IMovie implementation registered
         Component.For<IMovie>().ImplementedBy<Movie>()
  );


Amir Barylko - Advanced IoC                           MavenThought Inc.
GENERICS

  •What If I want to register a generic class?
  container.Register(

         Component

                .For(typeof(IRepository<>)

                .ImplementedBy(typeof(NHRepository<>)

  );




Amir Barylko - Advanced IoC                             MavenThought Inc.
DEPENDENCIES
  Component
        .For<IMovieFactory>()
        .ImplementedBy<NHMovieFactory>(),

  Component
        .For<IMovieRepository>()
        .ImplementedBy<SimpleMovieRepository>()


  public class SimpleMovieRepository : IMovieRepository
  {
      public SimpleMovieRepository(IMovieFactory factory)
      {
          _factory = factory;
      }
  }

Amir Barylko - Advanced IoC                            MavenThought Inc.
LIFESTYLE

  • Singleton      vs Transient

  • Which       one is the default? And for other IoC tools?

  container.Register(
     Component.For<IMovie>()
        .ImplementedBy<Movie>()
        .LifeStyle.Transient
     );


Amir Barylko - Advanced IoC                                    MavenThought Inc.
RELEASING

  • Do     I need to release the instances?




Amir Barylko - Advanced IoC                   MavenThought Inc.
NAMING

  • Who’s       the one resolved?
  container.Register(
         Component
            .For<IMovie>()
            .ImplementedBy<Movie>(),
         Component
            .For<IMovie>()
            .ImplementedBy<RottenTomatoesMovie>()
  );


Amir Barylko - Advanced IoC                         MavenThought Inc.
NAMING II

  • Assign     unique names to registration
  container.Register(
      ...

         Component
             .For<IMovie>()
             .ImplementedBy<RottenTomatoesMovie>()
             .Named("RT")
  );

  container.Resolve<IMovie>("RT");



Amir Barylko - Advanced IoC                          MavenThought Inc.
JOGGING
                                   Installers
                              Using Conventions
                                 Depend On




Amir Barylko - Advanced IoC                       MavenThought Inc.
INSTALLERS

  • Where        do we put the registration code?

  • Encapsulation

  • Partition      logic

  • Easy    to maintain




Amir Barylko - Advanced IoC                         MavenThought Inc.
INSTALLER EXAMPLE
  container.Install(
   new EntitiesInstaller(),
   new RepositoriesInstaller(),

   // or use FromAssembly!
   FromAssembly.This(),
   FromAssembly.Named("MavenThought...."),
   FromAssembly.Containing<ServicesInstaller>(),
   FromAssembly.InDirectory(new AssemblyFilter("...")),
   FromAssembly.Instance(this.GetPluginAssembly())
  );



Amir Barylko - Advanced IoC                   MavenThought Inc.
XML CONFIG
      var res = new AssemblyResource("assembly://.../
      ioc.xml")

  container.Install(
     Configuration.FromAppConfig(),
     Configuration.FromXmlFile("ioc.xml"),
     Configuration.FromXml(res)
     );




Amir Barylko - Advanced IoC                         MavenThought Inc.
CONVENTIONS
  Classes

       .FromAssemblyContaining<IMovie>()

       .BasedOn<IMovie>()

       .WithService.Base() // Register the service

       .LifestyleTransient() // Transient lifestyle




Amir Barylko - Advanced IoC                           MavenThought Inc.
CONFIGURE COMPONENTS
  Classes

     .FromAssemblyContaining<IMovie>()

     .BasedOn<IMovie>()

      .LifestyleTransient()

     // Using naming to identify instances

     .Configure(r => r.Named(r.Implementation.Name))




Amir Barylko - Advanced IoC                        MavenThought Inc.
DEPENDS ON
  var rtKey = @"the key goes here";
  container.Register(
     Component
      .For<IMovieFactory>()
      .ImplementedBy<RottenTomatoesFactory>()
     .DependsOn(Property.ForKey("apiKey").Eq(rtKey))
  );

  .DependsOn(new { apiKey = rtKey } ) // using anonymous class

  .DependsOn(
    new Dictionary<string,string>{
      {"APIKey", twitterApiKey}}) // using dictionary




Amir Barylko - Advanced IoC                               MavenThought Inc.
SERVICE OVERRIDE
  container.Register(
    Component
        .For<IMovieFactory>()
        .ImplementedBy<IMDBMovieFactory>()
        .Named(“imdbFactory”)

    Component
       .For<IMovieRepository>()
       .ImplementedBy<SimpleMovieRepository>()
       .DependsOn(Dependency.OnComponent("factory", "imdbFactory"))
  );




Amir Barylko - Advanced IoC                               MavenThought Inc.
RUN FOREST! RUN!
                                   Startable Facility
                              Interface Based Factories
                                     Castle AOP




Amir Barylko - Advanced IoC                               MavenThought Inc.
STARTABLE FACILITY

  • Allows      objects to be started when they are created

  • And     stopped when they are released

  • Start and stop methods have to be public, void and no
     parameters

  • You  can use it with POCO objects specifying which method
     to use to start and stop


Amir Barylko - Advanced IoC                              MavenThought Inc.
STARTABLE CLASS
  public interface IStartable
  {
      void Start();
      void Stop();
  }

  var container = new WindsorContainer()
      .AddFacility<StartableFacility>()
      .Register(
          Component
             .For<IThing>()
             .ImplementedBy<StartableThing>()
      );


Amir Barylko - Advanced IoC                     MavenThought Inc.
FACTORIES

  • Common          pattern to create objects

  • But    the IoC is some kind of factory too...

  • Each     factory should use the IoC then....

  • Unless      we use Windsor!!!!




Amir Barylko - Advanced IoC                         MavenThought Inc.
TYPED FACTORIES

  • Create      a factory based on an interface

  • Methods        that return values are Resolve methods

  • Methods        that are void are Release methods

  • Collection            methods resolve to multiple components




Amir Barylko - Advanced IoC                                  MavenThought Inc.
REGISTER FACTORY
  Kernel.AddFacility<TypedFactoryFacility>();

  Register(
      Component
         .For<IMovie>()
         .ImplementedBy<NHMovie>()
         .LifeStyle.Transient,

         Component.For<IMovieFactory>().AsFactory()
  );




Amir Barylko - Advanced IoC                           MavenThought Inc.
CASTLE AOP

  • Inject    code around methods

  • Cross     cutting concerns

  • Avoid      mixing modelling and usage

  • Avoid      littering the code with new requirements




Amir Barylko - Advanced IoC                               MavenThought Inc.
INTERCEPTORS
  Register(
      Component
          .For<LoggingInterceptor>()
          .LifeStyle.Transient,
      Component
          .For<IMovie>()
          .ImplementedBy<NHMovie>()
          .Interceptors(InterceptorReference
                          .ForType<LoggingInterceptor>()).Anywhere
          .LifeStyle.Transient
  );




Amir Barylko - Advanced IoC                               MavenThought Inc.
LOGGING
  public class LoggingInterceptor : IInterceptor
  {
      public void Intercept(IInvocation invocation)
      {
          Debug.WriteLine("Before execution");
          invocation.Proceed();
          Debug.WriteLine("After execution");
      }
  }




Amir Barylko - Advanced IoC                       MavenThought Inc.
NOTIFY PROPERTY CHANGED
  Register(
      Component
          .For<NotifyPropertyChangedInterceptor>()
          .LifeStyle.Transient,
      Component
          .For<IMovieViewModel>()
          .ImplementedBy<MovieViewModel>()
          .Interceptors(InterceptorReference
                       .ForType<NotifyPropertyChangedInterceptor>())
                       .Anywhere
          .LifeStyle.Transient
      );




Amir Barylko - Advanced IoC                               MavenThought Inc.
QUESTIONS?




Amir Barylko - TDD                MavenThought Inc.
RESOURCES

  • Contact: amir@barylko.com, @abarylko

  • Code      & Slides: http://www.orthocoders.com/presentations

  • Castle     Project Doc: http://docs.castleproject.org




Amir Barylko - Advanced IoC                                 MavenThought Inc.

Contenu connexe

Tendances

CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2Amir Barylko
 
prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-worldAmir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integrationAmir Barylko
 
PRDC11-tdd-common-mistakes
PRDC11-tdd-common-mistakesPRDC11-tdd-common-mistakes
PRDC11-tdd-common-mistakesAmir Barylko
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Mozaic Works
 
Android java fx-jme@jug-lugano
Android java fx-jme@jug-luganoAndroid java fx-jme@jug-lugano
Android java fx-jme@jug-luganoFabrizio Giudici
 
Automated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashAutomated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashNiels Frydenholm
 
20110903 candycane
20110903 candycane20110903 candycane
20110903 candycaneYusuke Ando
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Niels Frydenholm
 
Intro to Continuous Integration at SoundCloud
Intro to Continuous Integration at SoundCloudIntro to Continuous Integration at SoundCloud
Intro to Continuous Integration at SoundCloudgarriguv
 

Tendances (11)

CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2CodeCamp 2012-mvc-vs-ror-2
CodeCamp 2012-mvc-vs-ror-2
 
prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-world
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 
PRDC11-tdd-common-mistakes
PRDC11-tdd-common-mistakesPRDC11-tdd-common-mistakes
PRDC11-tdd-common-mistakes
 
obs-tdd-intro
obs-tdd-introobs-tdd-intro
obs-tdd-intro
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Android java fx-jme@jug-lugano
Android java fx-jme@jug-luganoAndroid java fx-jme@jug-lugano
Android java fx-jme@jug-lugano
 
Automated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/CalabashAutomated UI test on mobile - with Cucumber/Calabash
Automated UI test on mobile - with Cucumber/Calabash
 
20110903 candycane
20110903 candycane20110903 candycane
20110903 candycane
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...
 
Intro to Continuous Integration at SoundCloud
Intro to Continuous Integration at SoundCloudIntro to Continuous Integration at SoundCloud
Intro to Continuous Integration at SoundCloud
 

Similaire à Codemash-advanced-ioc-castle-windsor

ioc-castle-windsor
ioc-castle-windsorioc-castle-windsor
ioc-castle-windsorAmir Barylko
 
Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))dev2ops
 
Introduction to IoC Container
Introduction to IoC ContainerIntroduction to IoC Container
Introduction to IoC ContainerGyuwon Yi
 
PRDCW-avent-aggregator
PRDCW-avent-aggregatorPRDCW-avent-aggregator
PRDCW-avent-aggregatorAmir Barylko
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptAmir Barylko
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureZachary Klein
 
Pimp Your Pipeline - Central Configuration Management - Jens Saade
Pimp Your Pipeline - Central Configuration Management - Jens SaadePimp Your Pipeline - Central Configuration Management - Jens Saade
Pimp Your Pipeline - Central Configuration Management - Jens Saadeyoungculture
 
Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1Codecamp Romania
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOCCarl Lu
 
Istio Upgrade Field Guide IstioCon2022.pdf
Istio Upgrade Field Guide IstioCon2022.pdfIstio Upgrade Field Guide IstioCon2022.pdf
Istio Upgrade Field Guide IstioCon2022.pdfRam Vennam
 
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.VitaliyMakogon
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java binOlve Hansen
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EEhwilming
 
Spring training
Spring trainingSpring training
Spring trainingTechFerry
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019RackN
 

Similaire à Codemash-advanced-ioc-castle-windsor (20)

ioc-castle-windsor
ioc-castle-windsorioc-castle-windsor
ioc-castle-windsor
 
Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))
 
Introduction to IoC Container
Introduction to IoC ContainerIntroduction to IoC Container
Introduction to IoC Container
 
PRDCW-avent-aggregator
PRDCW-avent-aggregatorPRDCW-avent-aggregator
PRDCW-avent-aggregator
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; Coffeescript
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
 
Pimp Your Pipeline - Central Configuration Management - Jens Saade
Pimp Your Pipeline - Central Configuration Management - Jens SaadePimp Your Pipeline - Central Configuration Management - Jens Saade
Pimp Your Pipeline - Central Configuration Management - Jens Saade
 
Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
 
Istio Upgrade Field Guide IstioCon2022.pdf
Istio Upgrade Field Guide IstioCon2022.pdfIstio Upgrade Field Guide IstioCon2022.pdf
Istio Upgrade Field Guide IstioCon2022.pdf
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java bin
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 
Tdd patterns1
Tdd patterns1Tdd patterns1
Tdd patterns1
 
Spring training
Spring trainingSpring training
Spring training
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019
 

Plus de Amir Barylko

Functional converter project
Functional converter projectFunctional converter project
Functional converter projectAmir Barylko
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep diveAmir Barylko
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting trainingAmir Barylko
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessAmir Barylko
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideAmir Barylko
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityAmir Barylko
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilitiesAmir Barylko
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescriptAmir Barylko
 
SDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescriptSDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescriptAmir Barylko
 

Plus de Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
SDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescriptSDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescript
 

Dernier

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Dernier (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Codemash-advanced-ioc-castle-windsor

  • 1. AMIR BARYLKO ADVANCED IOC WINDSOR CASTLE Amir Barylko - Advanced IoC MavenThought Inc.
  • 2. FIRST STEPS Why IoC containers Registering Components LifeStyles Naming Amir Barylko - Advanced IoC MavenThought Inc.
  • 3. WHY USE IOC • Manage creation and disposing objects • Avoid hardcoding dependencies • Dependency injection • Dynamically configure instances • Additional features Amir Barylko - Advanced IoC MavenThought Inc.
  • 4. REGISTRATION • In order to resolve instances, we need to register them Container.Register( // Movie class registered Component.For<Movie>(), // IMovie implementation registered Component.For<IMovie>().ImplementedBy<Movie>() ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 5. GENERICS •What If I want to register a generic class? container.Register( Component .For(typeof(IRepository<>) .ImplementedBy(typeof(NHRepository<>) ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 6. DEPENDENCIES Component .For<IMovieFactory>() .ImplementedBy<NHMovieFactory>(), Component .For<IMovieRepository>() .ImplementedBy<SimpleMovieRepository>() public class SimpleMovieRepository : IMovieRepository { public SimpleMovieRepository(IMovieFactory factory) { _factory = factory; } } Amir Barylko - Advanced IoC MavenThought Inc.
  • 7. LIFESTYLE • Singleton vs Transient • Which one is the default? And for other IoC tools? container.Register( Component.For<IMovie>() .ImplementedBy<Movie>() .LifeStyle.Transient ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 8. RELEASING • Do I need to release the instances? Amir Barylko - Advanced IoC MavenThought Inc.
  • 9. NAMING • Who’s the one resolved? container.Register( Component .For<IMovie>() .ImplementedBy<Movie>(), Component .For<IMovie>() .ImplementedBy<RottenTomatoesMovie>() ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 10. NAMING II • Assign unique names to registration container.Register( ... Component .For<IMovie>() .ImplementedBy<RottenTomatoesMovie>() .Named("RT") ); container.Resolve<IMovie>("RT"); Amir Barylko - Advanced IoC MavenThought Inc.
  • 11. JOGGING Installers Using Conventions Depend On Amir Barylko - Advanced IoC MavenThought Inc.
  • 12. INSTALLERS • Where do we put the registration code? • Encapsulation • Partition logic • Easy to maintain Amir Barylko - Advanced IoC MavenThought Inc.
  • 13. INSTALLER EXAMPLE container.Install( new EntitiesInstaller(), new RepositoriesInstaller(), // or use FromAssembly! FromAssembly.This(), FromAssembly.Named("MavenThought...."), FromAssembly.Containing<ServicesInstaller>(), FromAssembly.InDirectory(new AssemblyFilter("...")), FromAssembly.Instance(this.GetPluginAssembly()) ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 14. XML CONFIG var res = new AssemblyResource("assembly://.../ ioc.xml") container.Install( Configuration.FromAppConfig(), Configuration.FromXmlFile("ioc.xml"), Configuration.FromXml(res) ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 15. CONVENTIONS Classes .FromAssemblyContaining<IMovie>() .BasedOn<IMovie>() .WithService.Base() // Register the service .LifestyleTransient() // Transient lifestyle Amir Barylko - Advanced IoC MavenThought Inc.
  • 16. CONFIGURE COMPONENTS Classes .FromAssemblyContaining<IMovie>() .BasedOn<IMovie>() .LifestyleTransient() // Using naming to identify instances .Configure(r => r.Named(r.Implementation.Name)) Amir Barylko - Advanced IoC MavenThought Inc.
  • 17. DEPENDS ON var rtKey = @"the key goes here"; container.Register( Component .For<IMovieFactory>() .ImplementedBy<RottenTomatoesFactory>()    .DependsOn(Property.ForKey("apiKey").Eq(rtKey)) ); .DependsOn(new { apiKey = rtKey } ) // using anonymous class .DependsOn( new Dictionary<string,string>{ {"APIKey", twitterApiKey}}) // using dictionary Amir Barylko - Advanced IoC MavenThought Inc.
  • 18. SERVICE OVERRIDE container.Register(   Component .For<IMovieFactory>() .ImplementedBy<IMDBMovieFactory>() .Named(“imdbFactory”)   Component .For<IMovieRepository>() .ImplementedBy<SimpleMovieRepository>()      .DependsOn(Dependency.OnComponent("factory", "imdbFactory")) ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 19. RUN FOREST! RUN! Startable Facility Interface Based Factories Castle AOP Amir Barylko - Advanced IoC MavenThought Inc.
  • 20. STARTABLE FACILITY • Allows objects to be started when they are created • And stopped when they are released • Start and stop methods have to be public, void and no parameters • You can use it with POCO objects specifying which method to use to start and stop Amir Barylko - Advanced IoC MavenThought Inc.
  • 21. STARTABLE CLASS public interface IStartable { void Start(); void Stop(); } var container = new WindsorContainer() .AddFacility<StartableFacility>() .Register( Component .For<IThing>() .ImplementedBy<StartableThing>() ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 22. FACTORIES • Common pattern to create objects • But the IoC is some kind of factory too... • Each factory should use the IoC then.... • Unless we use Windsor!!!! Amir Barylko - Advanced IoC MavenThought Inc.
  • 23. TYPED FACTORIES • Create a factory based on an interface • Methods that return values are Resolve methods • Methods that are void are Release methods • Collection methods resolve to multiple components Amir Barylko - Advanced IoC MavenThought Inc.
  • 24. REGISTER FACTORY Kernel.AddFacility<TypedFactoryFacility>(); Register( Component .For<IMovie>() .ImplementedBy<NHMovie>() .LifeStyle.Transient, Component.For<IMovieFactory>().AsFactory() ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 25. CASTLE AOP • Inject code around methods • Cross cutting concerns • Avoid mixing modelling and usage • Avoid littering the code with new requirements Amir Barylko - Advanced IoC MavenThought Inc.
  • 26. INTERCEPTORS Register( Component .For<LoggingInterceptor>() .LifeStyle.Transient, Component .For<IMovie>() .ImplementedBy<NHMovie>() .Interceptors(InterceptorReference .ForType<LoggingInterceptor>()).Anywhere .LifeStyle.Transient ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 27. LOGGING public class LoggingInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { Debug.WriteLine("Before execution"); invocation.Proceed(); Debug.WriteLine("After execution"); } } Amir Barylko - Advanced IoC MavenThought Inc.
  • 28. NOTIFY PROPERTY CHANGED Register( Component .For<NotifyPropertyChangedInterceptor>() .LifeStyle.Transient, Component .For<IMovieViewModel>() .ImplementedBy<MovieViewModel>() .Interceptors(InterceptorReference .ForType<NotifyPropertyChangedInterceptor>()) .Anywhere .LifeStyle.Transient ); Amir Barylko - Advanced IoC MavenThought Inc.
  • 29. QUESTIONS? Amir Barylko - TDD MavenThought Inc.
  • 30. RESOURCES • Contact: amir@barylko.com, @abarylko • Code & Slides: http://www.orthocoders.com/presentations • Castle Project Doc: http://docs.castleproject.org Amir Barylko - Advanced IoC MavenThought Inc.