Object-Relational Mapping and Dependency Injection

1,599 views
1,364 views

Published on

Presentation for El Paso County IT on the concepts of Object-Relational Mapping and Dependency injection with a particular focus on the Microsoft Unity DI Container and the Microsoft Entity Framework. Delivered on October 2, 2012.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,599
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • .NET ORM tools for databases include EF, NHibernate, TelerikOpenAccess, Castle ActiveRecord.NET Object to Object Mappers include tools like AutoMapper
  • .NET Implementations: Microsoft Unity, Castle Windsor, StructureMap, Ninject
  • Object-Relational Mapping and Dependency Injection

    1. 1. Object-Relational Mapping and Dependency Injection
    2. 2. Object-Relational MappingORM Concepts
    3. 3. What is ORM?• Object Relational Mapping is a technique for converting between incompatible type systems in Object Oriented (OO) programming.• Primary use is to map between business objects in the application layer and a relational database.• Also can be used to map from business object models to data transfer objects (DTO) or a view model.
    4. 4. ORM Advantages and Disadvantages• Compared to traditional techniques of exchange between an object-oriented language and a relational database, ORM often reduces the amount of code that needs to be written.• Compared to traditional techniques, ORM greatly improves the speed of application development.• ORM tools add complexity in areas where proprietary, or database-specific techniques have been highly optimized.• Most ORM tools do not perform well during bulk deletions of data or joins.• Stored procedures may have better performance, but are not portable.• Object-relational impedance mismatch can result if the business object model does not closely match the relational data structure.
    5. 5. .NET ORM Tools• Entity Framework: http://msdn.microsoft.com/data/ef• Telerik OpenAccess: http://www.telerik.com/products/orm.aspx• Castle Project: http://www.castleproject.org/• AutoMapper: https://github.com/AutoMapper/AutoMapper
    6. 6. Microsoft Entity FrameworkWhy EF?
    7. 7. What is the Entity Framework (EF)?• EF is Microsoft’s recommended data access technology for new applications.• EF is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects.• Supported Databases • SQL Server • MySQL • Oracle • Sybase • Any other database that provides an ADO.NET data provider
    8. 8. EF Use Patterns• Database First• Model First• Code First • Code First Migrations
    9. 9. Inversion of Control and Dependency Injection
    10. 10. What is Inversion of Control (IoC)?• IoC is an object-oriented programming practice where the object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.• Inversion of control as a design guideline serves the following purposes: • There is a decoupling of the execution of a certain task from implementation. • Every module can focus on what it is designed for. • Modules make no assumptions about what other systems do but rely on their contracts. • Replacing modules has no side effect on other modules.
    11. 11. What is Dependency Injection (DI)?• DI is a software design pattern that allows a choice of component to be made at run-time rather than compile time.• The binding of objects in the IoC pattern is accomplished through DI.• Dependency injection involves at least three elements: • A dependent consumer, • A declaration of a components dependencies, defined as interface contracts, • An injector (usually referred to as a container) that creates instances of classes that implement a given dependency interface on request.
    12. 12. Why use IoC and DI?• Encourages Separation of Concerns• Facilitates unit testing by allowing mock object with known behaviors to be injected• Promotes loose coupling between application layers, allowing implementations to be changed as necessary (i.e. mocks to SQL Server to Oracle)
    13. 13. .NET Dependency Injection Frameworks• Unity DI Container: http://unity.codeplex.com/• Ninject: http://www.ninject.org/• StructureMap: http://docs.structuremap.net/• Spring.NET: http://www.springframework.net/
    14. 14. Microsoft Unity DI ContainerWhy Unity?
    15. 15. What is Unity and Why Use It?• The Unity Application Block (Unity) is a lightweight extensible dependency injection container• Unity is developed and maintained by the Microsoft Patterns and Practices team• Unity is fully configurable using standard .NET config file patterns or through code initialization
    16. 16. Recommended Tool Links• Entity Framework: http://msdn.microsoft.com/data/ef• Unity DI Container: http://unity.codeplex.com/
    17. 17. Questions and Discussion

    ×