Tworzenie elastycznych aplikacji .NET w oparciu o wzorce projektowe Inversion Of Control i Dependency Injection

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Kilka luźnych pomysłów realizacji injekcji dla komponentów1) Automatyczna rejestracja dla ładowanych assemblies z komponentamiPodczas inicjalizacji aplikacji hosta:AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnCurrentDomainAssemblyLoad);static void OnCurrentDomainAssemblyLoad(object sender, AssemblyLoadEventArgs args){ IEnumerable types = args.LoadedAssembly.GetTypes() .Where(t => typeof(IContainerConfigurator).IsAssignableFrom(t)); foreach (Type t in types) { var configurator = Activator.CreateInstance(t) as IContainerConfigurator; var container = Application["container"] as IUnityContainer; var childContainer = container.CreateChildContainer(); configurator.Configure(childContainer) }}2) Warstwa fabryk oprartych o wsparcie dla hierarchicznych kontenerów dostępne m.in. w Unity. LogicFactory(){ CreateOrderProcessor() { using (var ctx = new CurrentContainerScope()) // if current container exists in TLS, creates subcontainer within it if not creates new container { if (!ctx.HasMappingDefined) { ctx.Register(); } if (!ctx.HasMappingDefined) { ctx.Register(); } return ctx.Resolve(); // dzieki temu mozemy uzywac AOP itp. } } CreateEngine(EngineType type) { using (var ctx = new CurrentContainer()) // decorates the current container from TLS { if (!ctx.HasMappingDefined) { ctx.Register(); } var result = new Engine(type); ctx.BuildUp(result); return result; } }}

    W kolejnej wersji (2.0) Unity „pochłonie” klasy ObjectBuildera (nie będzie konieczności referencjonowania assembly ObjectBuildera).

    Favorites, Groups & Events

    Tworzenie elastycznych aplikacji .NET w oparciu o wzorce projektowe Inversion Of Control i Dependency Injection - Presentation Transcript

    1. Tworzenie elastycznych aplikacji .NET w oparciu o wzorce projektoweInversion Of Control i DependencyInjection
      Marcin Daczkowski, AIS.PL
      marcin.daczkowski@ais.pl
    2. Agenda
      Charakterystyka
      Zalety i wady
      Warianty
      Zastosowania
      Przegląd kontenerów
      Unity
      Architektura
      Przykłady użycia
    3. Charakterystyka
    4. Każdy wzorzec określa problem,
      który wielokrotniewystępuje w naszym środowisku,
      a następnie opisuje zasadniczączęśćrozwiązaniatego problemu.
      Christopher Alexander (1977)
      A Pattern Language: Towns, Buildings, Construction
    5. Inversion of Control
      Wzorzec architektoniczny
      Przeniesienie odpowiedzialności
      • Różne aspekty
      • Sterowanie
      • Determinowanie powiązań
    6. Dependency Injection
      Autor - Martin Fowler
      Rozwiązuje ten sam problem, co wzorce kreacyjne:
      Fabryka Abstrakcyjna
      Metoda Wytwórcza
      Budowniczy
      Zgodnie z ideą Inversion of Control
      Bob Martin - SOLID
    7. Tight-coupling
      tworzy
      A
      B
      C
      używa
      używa
    8. DependencyInjection
      tworzy
      A
      B
      IC
      używa
      używa
    9. DependencyInjection + Kontener
      tworzy
      A
      B
      Kontener DI
      IC
      używa
      używa
      używa
    10. Service Locator
      tworzy
      A
      B
      Service
      Locator
      IC
      używa
      używa
      używa
    11. Zalety i wady
    12. Warianty
    13. ConstructorInjection
      new B(new C());
      IC
      public B( ) { }
      • Property Injection
      var b = new B();
      b.C = new C();
      IC
      public { set; }
    14. InterfaceInjection
      IC
      voidInjectC( c)
      var b = new B();
      b.InjectC(new C());
      B : IInjectC
    15. Zastosowania
    16. Hosty aplikacyjne
      Windows Forms
      WPF
      ASP.NET Web Forms
      ASP.NET MVC
      WCF

    17. Biblioteki
      Prywatne kontenery
      Kontener współdzielony z hostem
      Integracja poprzez mechanizmy rozszerzeń
    18. Przegląd kontenerów
    19. Ninject
      Autofac
      Structure Map
      Unity
      Castle Windsor
      Spring.NET
      Wybrane rozwiązania
    20. Źródło: http://www.codinginstinct.com/2008/04/ioc-container-benchmark-unity-windsor.html
    21. Unity
    22. Unity
      ObjectBuilder
    23. Konfiguracja
      AOP
      Atrybuty
      ObjectBuilder
      Typy
      Generyczne
      Lifetime
      Managers
      Tablice

      StaticFactory
    24. Policy
      Policy
      Policy
      ObjectBuilder 2.0
      Strategy
      Strategy
      Strategy


      Locator
      Lifetimecontainer
    25. DEMO
    26. Pytania?

    + merdaczmerdacz, 2 months ago

    custom

    133 views, 0 favs, 0 embeds more stats

    Originally presented on IT Academic Day 2008 (Facul more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 133
      • 133 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories